1个不稳定版本
使用旧的Rust 2015
0.1.2 | 2022年3月10日 |
---|
#13 在 #bcrypt
7KB
109 行
更新了Easy密码哈希
支持算法
- Bcrypt
动机
原始库(https://github.com/ChrisPWill/easy_password)无法编译,所以我克隆并更新了库。
直接使用Bcrypt会导致密码长度限制为72。这意味着很难对密码进行加盐或支持任意长度的用户密码。
此库在将结果输入Bcrypt之前,使用SHA256作为哈希函数对密码执行HMAC。因此,当使用此库生成或验证密码时,可以使用任意长度的密码。
使用方法
哈希密码
extern crate easy_password;
use easy_password::bcrypt::hash_password;
let bcrypt_rounds = 12; // Secure default
let hash: String =
hash_password("my_password", b"secure_key", 12).unwrap();
验证哈希
extern crate easy_password;
use easy_password::bcrypt::hash_password;
let success: bool =
verify_password("test_password", hash.as_str(), b"secure_key").unwrap();
许可证
MIT许可证
依赖项
~1.5MB
~25K SLoC