bcryptjs
Posted Surahe
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bcryptjs相关的知识,希望对你有一定的参考价值。
同步用法
To hash a password:
var bcrypt = require(‘bcryptjs‘); var salt = bcrypt.genSaltSync(10); var hash = bcrypt.hashSync("B4c0/\/", salt); // Store hash in your password DB.
To check a password:
// Load hash from your password DB. bcrypt.compareSync("B4c0/\/", hash); // true bcrypt.compareSync("not_bacon", hash); // false
Auto-gen a salt and hash:
var hash = bcrypt.hashSync(‘bacon‘, 8);
异步用法
To hash a password:
var bcrypt = require(‘bcryptjs‘); bcrypt.genSalt(10, function(err, salt) { bcrypt.hash("B4c0/\/", salt, function(err, hash) { // Store hash in your password DB. }); });
To check a password:
// Load hash from your password DB. bcrypt.compare("B4c0/\/", hash, function(err, res) { // res == true }); bcrypt.compare("not_bacon", hash, function(err, res) { // res = false });
Auto-gen a salt and hash:
bcrypt.hash(‘bacon‘, 8, function(err, hash) { });
以上是关于bcryptjs的主要内容,如果未能解决你的问题,请参考以下文章
如何修复 TypeError:在使用 bcryptjs 对 GraphQL 突变进行哈希密码期间无法读取未定义的属性“哈希”?