加密 防撞库

1

> npm install --save bcryptjs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

const bcrypt = require('bcryptjs')
var password = '123abc!';

//加密, salt password 是为了防止撞库***、密码概率***
bcrypt.genSalt(10, (err, salt) => {
bcrypt.hash(password, salt, (err, hash) => {
console.log(hash);
});
});

//解密
var hashedPassword = '$2a$10$huAU4qTnQuGPifHEXfV9cOmPJ7p61oKaoXrY1WviiDAznE/rW8oLK';

bcrypt.compare('123abc!', hashedPassword, (err, res) => {
console.log(res);
});

本文链接:https://dreamerjonson.com/2018/11/29/node-26-password-hash/

版权声明:本博客所有文章除特别声明外,均采用CC BY 4.0 CN协议许可协议。转载请注明出处!