nodejs 密码加密bcrypt
2020年11月11日1 安装bcrypt
|
1 |
npm install bcrypt |
2 安装 bcrypt 依赖的其他环境
1.安装python 2.7
|
1 |
apt-get install python |
2.安装 node-gyp
|
1 |
npm install -g node-gyp |
3.如果是windows系统以来 windows-build-tools
|
1 |
npm install --global --production windows-build-tools |
3.基本使用
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
const bcrypt = require('bcrypt') //引入bcrypt //异步方法 async function test() { const salt = await bcrypt.genSalt(10); //生成盐 const result = await bcrypt.hash('123123', salt); //hash 明文加盐 const isValid = await bcrypt.compare('123123', result) //检验密码是否正确 console.log(salt) console.log(result) console.log(isValid) } test(); |