bcryptjs#hashSync TypeScript Examples
The following examples show how to use
bcryptjs#hashSync.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: app.controller.ts From NestJs-youtube with MIT License | 6 votes |
@Post('auth/register')
async register(@Body() body: Partial<UserEntity>) {
try {
const salt = await genSalt(10);
const { password, ...reset } = body;
const u: Partial<UserEntity> = {
salt,
...reset,
password: hashSync(password, salt),
role: Roles.user,
};
const user = await this.authService.register(u);
const logedInUser = await this.authService.login(user);
delete logedInUser.password;
delete logedInUser.salt;
return logedInUser;
} catch (error) {
throw error;
}
}
Example #2
Source File: auth.service.ts From NestJs-youtube with MIT License | 6 votes |
async validateUser(
email: string,
pass: string,
): Promise<Partial<UserEntity>> {
const user = await this.userService.findOne(null, { where: { email } });
if (user && user.password === hashSync(pass, user.salt)) {
const { salt, password, ...u } = user;
return u;
}
return null;
}
Example #3
Source File: seed.class.ts From NestJs-youtube with MIT License | 6 votes |
private userData(): Array<Partial<UserEntity>> {
return this.arr().map<Partial<UserEntity>>(() => ({
email: internet.email(),
name: `${name.firstName()} ${name.lastName()}`,
role: random.arrayElement([
...Array.from({ length: 5 }).fill(Roles.user),
Roles.admin,
]),
about: lorem.sentences(),
password: hashSync('secret', this.salt),
salt: this.salt,
}));
}
Example #4
Source File: App.tsx From js-examples with MIT License | 6 votes |
generatePrivateKey = async (): Promise<PrivateKey> => {
const metamask = await this.getAddressAndSigner()
// avoid sending the raw secret by hashing it first
const secret = hashSync(this.state.secret, 10)
const message = this.generateMessageForEntropy(metamask.address, 'textile-demo', secret)
const signedText = await metamask.signer.signMessage(message);
const hash = utils.keccak256(signedText);
if (hash === null) {
throw new Error('No account is provided. Please provide an account to this application.');
}
// The following line converts the hash in hex to an array of 32 integers.
// @ts-ignore
const array = hash
// @ts-ignore
.replace('0x', '')
// @ts-ignore
.match(/.{2}/g)
.map((hexNoPrefix) => BigNumber.from('0x' + hexNoPrefix).toNumber())
if (array.length !== 32) {
throw new Error('Hash of signature is not the correct size! Something went wrong!');
}
const identity = PrivateKey.fromRawEd25519Seed(Uint8Array.from(array))
console.log(identity.toString())
this.createNotification(identity)
// Your app can now use this identity for generating a user Mailbox, Threads, Buckets, etc
return identity
}