加密

  1. // npm install bcryptjs
  2. // 之所以没有才有md5加密,是因为 bcryptjs 比md5更安全
  3. const password = "123456"
  4. const salt = bcrypt.genSaltSync(10)
  5. const hash = bcrypt.hashSync(password, salt) // hash就是加密的代码
  6. // PS:
  7. 1. bcrypt 依赖比较多
  8. 2. node-gyp
  9. 3. bcryptjs 不需要依赖,比较友好
  10. 4. npm i bcryptjs

解密

  1. bcrypt.compareSync("用户输入的密码", "数据库中保存的密码")