1 Star 0 Fork 0

TTANF_1/blog-demo

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
test-bcrypt.js 781 Bytes
Copy Edit Raw Blame History
TTANF_1 authored 2020-03-11 18:44 . login finished
// npm i bcrypt
// npm i bcryptjs
// 优先装bcrypt,如果装不了,就装bcryptjs
const bcrypt = require('bcrypt')
;(async () => {
// 生成加密盐
// 默认值是10,可以不填
// 这个数越大,生成的加密盐复杂度越大,但是耗费的资源就越大(CPU)
// 我们一般用默认值就够了
const salt = await bcrypt.genSalt()
console.log('生成出来的加密盐:', salt)
// 结合盐,加密明文密码:qwe123,返回加密后的密码
const pwd = await bcrypt.hash('qwer1234', salt)
console.log('加密后的密码:', pwd)
// 比对密码,返回结果(布尔值),true: 相等,false:不相等
const isEquality = await bcrypt.compare('qwer1234', pwd)
console.log('比对结果:', isEquality)
})()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ttanf_1/blog-demo.git
git@gitee.com:ttanf_1/blog-demo.git
ttanf_1
blog-demo
blog-demo
master

Search

0d507c66 1850385 C8b1a773 1850385