ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[toc] ## pre ``` UserSchema.pre('save', function (next) { //第一步先生成盐值 bcrypt.genSalt((err, salt) => { //通过原始的密码和盐值计算哈希值 bcrypt.hash(this.password, salt, (err, hash) => { this.password = hash; next(); }); }); }); ```