1.安装bcryptjs模块

npm install bcryptjs --save

2.在需要加密的模块中引入bcryptjs库 

'bcryptjs');

 
实战 :
/**
 * 定义数据库模型
 */

const userSchema = new mongoose.Schema({
    username:{
        type:String,
        unique:true
    },
    password:{
        type:String,
        set(val){
            return require('bcryptjs').hashSync(val)
        }
    }
})
 

相关文章:

  • 2022-02-25
  • 2022-01-26
  • 2022-12-23
  • 2021-11-19
  • 2021-09-23
猜你喜欢
  • 2022-01-11
  • 2021-11-19
  • 2021-11-21
  • 2022-12-23
  • 2021-07-28
  • 2022-12-23
  • 2021-08-25
相关资源
相似解决方案