本文整理汇总了TypeScript中bcryptjs.genSaltSync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript genSaltSync函数的具体用法?TypeScript genSaltSync怎么用?TypeScript genSaltSync使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了genSaltSync函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: hashPassword
function hashPassword(password: string): string {
if (!password) {
return null;
}
return Bcrypt.hashSync(password, Bcrypt.genSaltSync(8));
}
示例2: async
export default async (event: FunctionEvent<EventData>) => {
console.log(event);
try {
const graphcool = fromEvent(event);
const api = graphcool.api('simple/v1');
const { email, password } = event.data;
if (!validator.isEmail(email)) {
return { error: 'Not a valid email' };
}
// check if user exists already
const userExists: boolean = await getUser(api, email).then(
r => r.User !== null,
);
if (userExists) {
return { error: 'Email already in use' };
}
// create password hash
const salt = bcrypt.genSaltSync(SALT_ROUNDS);
const hash = await bcrypt.hash(password, SALT_ROUNDS);
// create new user
const userId = await createGraphcoolUser(api, email, hash);
// generate node token for new User node
const token = await graphcool.generateNodeToken(userId, 'User');
return { data: { id: userId, token } };
} catch (e) {
console.log(e);
return { error: 'An unexpected error occured during signup.' };
}
};
示例3: hashPasswd
export function hashPasswd(password: string): string {
const salt = bcrypt.genSaltSync(10);
const hash = bcrypt.hashSync(password, salt);
return hash;
}
示例4: generateHash
generateHash(password) {
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
}
示例5:
const hash_password = ( password ) => {
let salt = bcrypt.genSaltSync(); // enter number of rounds, default: 10
let hash = bcrypt.hashSync( password, salt );
return hash;
};