本文整理汇总了TypeScript中bcrypt.compareSync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript compareSync函数的具体用法?TypeScript compareSync怎么用?TypeScript compareSync使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了compareSync函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
.then(user => {
if (bcrypt.compareSync(password, user.password)) {
return UserModel.fromEntity(user);
} else {
return null;
}
});
示例2: reject
.then((accountOrganizationMember: AccountOrganizationMember) => {
if (!bcrypt.compareSync(data.password, ObjectUtil.getStringUnionProperty(accountOrganizationMember.user, 'password'))) {
return reject(new Error('Invalid password'));
}
resolve(accountOrganizationMember.user);
})
示例3: reject
.then((user: User) => {
if (ObjectUtil.isBlank(user)) {
return reject(new Error('The user does not exist within this organization'));
}
if (!bcrypt.compareSync(data.password, user.password)) {
return reject(new Error('Invalid password'));
}
resolve(user);
})
示例4: authSuccess
authSuccess(res:Response, credentials: any, data:any){
const isMatch = bcrypt.compareSync(credentials.password, data.password);
if(isMatch){
const payload = {
id: data.id
}
res.json({
token : jwt.encode(payload, config.secret)
});
}
else{
res.sendStatus(httpStatus.UNAUTHORIZED);
}
}
示例5: function
updateRecord = async function(id,data, model){
let
user,
res;
try {
user = await model.$findById('id', id, [1]);
} catch(err) {
return Promise.reject(err);
}
try {
res = await bcrypt.compareSync(`|-:${data.oldpwd}:-|`, user.password);
if(!res)
return errors.error({
code : '104'
});
let
_salt = bcrypt.genSaltSync(12),
_pwd = bcrypt.hashSync(`|-:${data.newpwd}:-|`, _salt);
/** TODO 此处用以下方式更新 password 会提示:
ValidationError: user validation failed
user.password = _pwd;
user = await user.save();
*/
let
update = await model.update({
_id : user._id
}, {
$set : {
password : _pwd
}
}).exec();
return update.ok === 1 ? errors.success(true) : errors.error({
code : '31'
});
} catch(err) {
return Promise.reject(err);
}
};
示例6:
User.findOne({name: req.body.name}).exec().then((user: UserModelInterface) => {
if (!(user && bcrypt.compareSync(req.body.password, user.password))) {
return Promise.resolve(res.json(message));
}
// creates the jwt toke with a 6 hours duration
// since jwt typing states sign returns void, we have
// to assert the return as any (string doesn't work)
let token = jwt.sign({name: user.name}, app.get('jwtSecret'), {
expiresIn: '6h'
}) as any;
let response: Comprobable = {success: true, token: token};
// returns the token with a success message
return Promise.resolve(res.json(response));
}, err => {
示例7: moment
cursor.next((err, row) => {
if (err && err.message.indexOf('No more rows in the cursor') > -1) {
res.status(404).end('User does not exist.');
} else {
const valid = bcrypt.compareSync(req.body.password, row.password);
if (valid) {
const exp = moment().add(3, "months").valueOf();
const user = {
userId: row.id, email: row.email, expires: exp, refresh_token: row.refresh_token, access_token: jwtoken.sign({ isAdmin: row.isAdmin }, config.SECRET, { issuer: row.id, expiresIn: exp })
};
res.set('Content-Type', 'application/json');
res.json(user);
} else if (!valid) {
res.status(500).end('The password you entered is incorrect')
}
}
})
示例8: function
createRecord = async function(data, model){
try{
let
res = await model.findOne({
name : data.name
}).where('_status').equals(1).select('password');
if(!res){
return errors.error({
code : '214'
});
}
res = await bcrypt.compareSync(`|-:${data.password}:-|`, res.password);
return res ? errors.success(res) : errors.error({
code : '214'
});
}catch(err){
return errors.format(err);
}
};
示例9: function
UserSchema.method("verifyPassword", function(password: string) {
return bcrypt.compareSync(password, this.local.password);
});
示例10: validateUserPassword
static validateUserPassword(password: string, encryptedPassword: string): boolean {
return bcrypt.compareSync(password, encryptedPassword);
}