gpt4 book ai didi

javascript - 将 bcrypt 哈希/验证函数转换为异步函数

转载 作者:搜寻专家 更新时间:2023-11-01 00:27:16 24 4
gpt4 key购买 nike

<分区>

该函数有效,出于可扩展性和生产方面的考虑,我想将这个确切的函数转换为异步函数。

userSchema.methods  =   {
checkPassword: function (inputPassword) {
return bcrypt.compareSync( inputPassword, this.password )
},
hashPassword: plainTextPassword => {
return bcrypt.hashSync( plainTextPassword, 10 )
}
}

userSchema.pre('save', function (next) {
if (!this.password) {
console.log('models/user.js =======NO PASSWORD PROVIDED=======')
next()
} else {
console.log('models/user.js hashPassword in pre save');
this.password = this.hashPassword(this.password)
next()
}
})

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com