本文整理汇总了TypeScript中bcryptjs.genSalt函数的典型用法代码示例。如果您正苦于以下问题:TypeScript genSalt函数的具体用法?TypeScript genSalt怎么用?TypeScript genSalt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了genSalt函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: function
UserSchema.pre('save', function (next: Function): void {
let user = this
// check if admin (no place needed)
if (!user.admin && !user.placeList) {
return next(new Error('palceList field needed'))
} else if (!user.admin && user.placeList.length === 0) {
return next(new Error('palceList field needed'))
}
// TODO validate placeList ids
// only hash the password if it has been modified or is new
if (user.isModified('password') || user.isNew) {
bcrypt.genSalt(SALT, (err1, salt) => {
if (err1) { return next(err1) }
bcrypt.hash(user.password, salt, (err2, hash) => {
if (err2) { return next(err2) }
user.password = hash
next()
})
})
} else {
next()
}
})
开发者ID:chipp972,项目名称:stock_manager_api,代码行数:28,代码来源:user.ts
示例2: async
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
// Get 'currentPasword' parameter
const [currentPassword, currentPasswordErr] = $.str.get(params.currentPasword);
if (currentPasswordErr) return rej('invalid currentPasword param');
// Get 'newPassword' parameter
const [newPassword, newPasswordErr] = $.str.get(params.newPassword);
if (newPasswordErr) return rej('invalid newPassword param');
// Compare password
const same = await bcrypt.compare(currentPassword, user.password);
if (!same) {
return rej('incorrect password');
}
// Generate hash of password
const salt = await bcrypt.genSalt(8);
const hash = await bcrypt.hash(newPassword, salt);
await User.update(user._id, {
$set: {
'password': hash
}
});
res();
});
开发者ID:ha-dai,项目名称:Misskey,代码行数:28,代码来源:change_password.ts
示例3: function
userSchema.pre('save', function (next) {
if (!this.isModified('password')) {return next(); }
bcrypt.genSalt(10, function(err, salt) {
if (err) {return next(err); }
bcrypt.hash(this.password, salt, function(error, hash) {
if (error) {return next(error); }
this.password = hash;
next();
});
});
});
开发者ID:pontsoleil,项目名称:WuWei,代码行数:11,代码来源:user.ts
示例4: function
UserSchema.pre('save', function (next) {
const user = this as IUserModel;
bcrypt.genSalt(10, (err, salt) => {
if (err) {
return next(err)
}
bcrypt.hash(user.password, salt, (err, hash) => {
if (err) {
return next(err)
}
user.password = hash;
next();
})
});
});
开发者ID:Antyneskul,项目名称:homeBudgetApi,代码行数:18,代码来源:user.ts
示例5: hash
export async function hash(password: string) {
const salt = await bcrypt.genSalt(10);
return bcrypt.hash(password, salt);
}
开发者ID:7h1b0,项目名称:Anna,代码行数:4,代码来源:cryptoUtil.ts
示例6: async
export default async (ctx: Koa.Context) => {
const body = ctx.request.body as any;
// Verify recaptcha
// ただしテスト時はこの機構は障害となるため無効にする
if (process.env.NODE_ENV !== 'test' && config.recaptcha != null) {
const success = await recaptcha(body['g-recaptcha-response']);
if (!success) {
ctx.throw(400, 'recaptcha-failed');
return;
}
}
const username = body['username'];
const password = body['password'];
// Validate username
if (!validateUsername(username)) {
ctx.status = 400;
return;
}
// Validate password
if (!validatePassword(password)) {
ctx.status = 400;
return;
}
// Fetch exist user that same username
const usernameExist = await User
.count({
usernameLower: username.toLowerCase(),
host: null
}, {
limit: 1
});
// Check username already used
if (usernameExist !== 0) {
ctx.status = 400;
return;
}
// Generate hash of password
const salt = await bcrypt.genSalt(8);
const hash = await bcrypt.hash(password, salt);
// Generate secret
const secret = generateUserToken();
// Create account
const account: IUser = await User.insert({
avatarId: null,
bannerId: null,
createdAt: new Date(),
description: null,
followersCount: 0,
followingCount: 0,
name: null,
notesCount: 0,
username: username,
usernameLower: username.toLowerCase(),
host: null,
keypair: generateKeypair(),
token: secret,
email: null,
password: hash,
profile: {
bio: null,
birthday: null,
blood: null,
gender: null,
handedness: null,
height: null,
location: null,
weight: null
},
settings: {
autoWatch: false
}
});
//#region Increment users count
Meta.update({}, {
$inc: {
'stats.usersCount': 1,
'stats.originalUsersCount': 1
}
}, { upsert: true });
//#endregion
// Response
ctx.body = await pack(account);
};
开发者ID:ha-dai,项目名称:Misskey,代码行数:95,代码来源:signup.ts
注:本文中的bcryptjs.genSalt函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论