bcryptjs
2016-03-07 11:30
666 查看
同步用法
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) { });
相关文章推荐
- JavaScript Array API
- JSPatch实现原理详解
- JS常用方法
- GeoJSON相关操作
- 关于url请求和json数据的响应的理解和接口的压力测试
- Javascript进阶篇——浏览器对象—History对象
- javascript改变指定的css样式
- 随着input里边值的变化而触发js事件
- js函数易犯的错误
- javascript特殊日历控件分享
- C json实战引擎 三 , 最后实现部分辅助函数
- PhantomJS入门
- js 重载i
- 添加json所报的异常
- js中document.write的那点事
- 记录--Gson、json转实体类、类转json
- 年月日 生日 js插件
- [转]跟我一起学extjs5(02--建立工程项目)
- JVM性能调优监控工具jps、jstack、jmap、jhat、jstat、hprof使用详解
- JS代码片段:一个日期离现在多久了