#apache #password #htpasswd

htpasswd-verify

验证存储在Apache的htpasswd文件中的散列

4个版本 (2个重大变更)

0.3.0 2023年2月17日
0.2.1 2021年10月30日
0.2.0 2021年7月19日
0.1.0 2019年11月1日

#2213 in 加密学

Download history 92/week @ 2024-03-12 63/week @ 2024-03-19 51/week @ 2024-03-26 75/week @ 2024-04-02 65/week @ 2024-04-09 68/week @ 2024-04-16 70/week @ 2024-04-23 62/week @ 2024-04-30 69/week @ 2024-05-07 49/week @ 2024-05-14 72/week @ 2024-05-21 62/week @ 2024-05-28 60/week @ 2024-06-04 68/week @ 2024-06-11 64/week @ 2024-06-18 54/week @ 2024-06-25

每月下载量256

Apache-2.0

23KB
450

htpasswd-verify

验证Apache的htpasswd文件

支持MD5、BCrypt、SHA1、Unix crypt

示例

验证MD5散列

let data = "user:$apr1$lZL6V/ci$eIMz/iKDkbtys/uU7LEK00";
let htpasswd = htpasswd_verify::Htpasswd::from(data);
assert!(htpasswd.check("user", "password"));

它还允许使用md5加密(不是实际的md5,而是htpasswd文件使用的Apache特定md5)

use htpasswd_verify::md5::{md5_apr1_encode, format_hash};

let password = "password";
let hash = md5_apr1_encode(password, "RandSalt");
let hash = format_hash(&hash, "RandSalt");
assert_eq!(hash, "$apr1$RandSalt$PgCXHRrkpSt4cbyC2C6bm/");

lib.rs:

验证Apache的htpasswd文件

支持MD5、BCrypt、SHA1、Unix crypt

示例

验证MD5散列

let data = "user:$apr1$lZL6V/ci$eIMz/iKDkbtys/uU7LEK00";
let htpasswd = htpasswd_verify::Htpasswd::from(data);
assert!(htpasswd.check("user", "password"));

创建[Htpasswd]而不借用数据

use htpasswd_verify::Htpasswd;

let htpasswd: Htpasswd<'static> = {
    let data = "\nuser:$apr1$lZL6V/ci$eIMz/iKDkbtys/uU7LEK00\n";
    // Trim the data to show that we're not using a 'static str
    let data = data.trim();
    Htpasswd::new_owned(data)
};

assert!(htpasswd.check("user", "password"));

它还允许使用md5加密(不是实际的md5,而是htpasswd文件使用的Apache特定md5)

use htpasswd_verify::md5::{md5_apr1_encode, format_hash};

let password = "password";
let hash = md5_apr1_encode(password, "RandSalt");
let hash = format_hash(&hash, "RandSalt");
assert_eq!(hash, "$apr1$RandSalt$PgCXHRrkpSt4cbyC2C6bm/");

依赖项

~5MB
~74K SLoC