本文整理汇总了TypeScript中bcrypt.genSalt函数的典型用法代码示例。如果您正苦于以下问题:TypeScript genSalt函数的具体用法?TypeScript genSalt怎么用?TypeScript genSalt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了genSalt函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
UserSchema.methods.regenerateJWTSalts = async function (): Promise<any> {
const salts: Array<string> = await Promise.all([
bcrypt.genSalt(config.get("security.SALT_LENGTH")),
bcrypt.genSalt(config.get("security.SALT_LENGTH"))
]);
this.jwtSecrets = {
access: salts[0],
refresh: salts[1]
};
return this.save();
};
示例2: function
userSchema.pre("save", function (next: Function) {
var user: any = this;
// only hash the password if it has been modified (or is new)
if (!user.isModified("password")) {
return next();
}
// generate a salt
bcrypt.genSalt(SALT_WORK_FACTOR, (err: any, salt: any) => {
if (err) {
return next(err);
}
// hash the password along with our new salt
bcrypt.hash(user.password, salt, (err2: any, hash: any) => {
if (err) {
return next(err2);
}
// override the cleartext password with the hashed one
user.password = hash;
next();
});
});
});
示例3: Promise
return new Promise(function (resolve, reject) {
bcrypt.genSalt(10, function(err, salt) {
bcrypt.hash(password, salt, function(err, hash) {
resolve(hash);
});
});
});
示例4: function
app.post('/signup', function(req, res) { //User "posts the info to the form"
let unhashedpassword = req.body.password;
bcrypt.genSalt(10, function(err, salt) {
bcrypt.hash(unhashedpassword, salt, function(err, hash) {
// Store hash in your password DB.
let user = new User({
username: req.body.username ,
email: req.body.email ,
password: hash
})
// save the user
user.save(function(err) {
if (err) throw err;
console.log('User saved successfully');
res.json({ success: true });
});
});
});
});
示例5: hashPassword
async hashPassword(password: string) {
const saltRounds = 10;
const salt = await bcrypt.genSalt(saltRounds);
try {
const hashedPassword = await bcrypt.hash(password, salt);
this.password = hashedPassword;
} catch(err) {}
}
示例6: function
userSchema.method('hashPassword', function(password, done) {
bcrypt.genSalt(10, (err, salt) => {
if (err) return done (err);
bcrypt.hash(password, salt, (err, hash) => {
if (err) return done (err);
done(null, hash);
});
});
});
示例7: Promise
return new Promise((resolve, reject) => {
bcrypt.genSalt((err, salt) => {
if (err) {
return reject(err);
}
return resolve(salt);
})
});
示例8: function
userSchema.method('hashPassword', function(password, done) {
bcrypt.genSalt(SALT_ROUNDS, (saltErr, salt) => {
/* istanbul ignore next */
if (saltErr) return done(saltErr);
bcrypt.hash(password, salt, (hashErr, hash) => {
/* istanbul ignore next */
if (hashErr) return done(hashErr);
done(null, hash);
});
});
});
示例9: genSalt
(req, res, next) =>
genSalt(10, function (err, salt) {
if (err) { return next(err); }
hash(req.body['passwd'], salt, (err, hashed) => (err) ? next(err)
:
db().none("INSERT INTO stakeholder(username, passwd, email, register_time, avatar) VALUES ($1, $2, $3, $4, $5)",
[ req.body['username'], hashed, req.body['email'], new Date(), config['blog']['default_avatar'] ])
.then(() => res.redirect('/user/login'),
(reason) => next(reason))
);
})
示例10: resolve
return new Promise<string>((resolve, reject) => {
bcrypt.genSalt(saltLength, (err, salt) => {
if (err) return reject(err);
bcrypt.hash(text, salt, (error, hash) => {
if (error) return reject(error);
return resolve(hash);
});
});
});