Express - password encryption using bcryptjs

1. Installation module bcryptjs

npm install bcryptjs --save

2. Introduction bcryptjs requiring encryption library module 

  require('bcryptjs');

 
Combat:
/**
 * Define database model
 */

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

Guess you like

Origin www.cnblogs.com/500m/p/11483307.html
Recommended