5个版本

0.1.4 2023年3月3日
0.1.3 2022年11月3日
0.1.2 2019年8月12日
0.1.1 2018年5月16日
0.1.0 2018年5月16日

#1872 in 加密

MIT许可证

8KB
104

简易密码散列

支持算法

  • Bcrypt

动机

直接使用Bcrypt会导致密码长度限制为72。这意味着难以加盐密码或支持任意长度的用户密码。

此库在将结果输入Bcrypt之前,使用SHA256作为哈希函数执行HMAC。因此,当使用此库创建或验证密码时,可以与Bcrypt一起使用任意长度的密码。

用法

散列密码

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();

代码审查

安装clippy

rustup component add clippy

进行代码审查

cargo clippy

应用所有建议的重构(别忘了重新格式化代码)

代码格式化

注意:目前只使用rustfmt的夜间版本进行格式化。项目本身是用最新的稳定版Rust编写和测试的。

安装rustfmt

rustup component add rustfmt --toolchain nightly

格式化代码

cargo +nightly fmt

许可证

MIT许可证,见LICENSE

依赖项

~1MB
~23K SLoC