#password #apache #sha-1 #htpasswd

htpasswd-verify

Verify hashes stored in apache's htpasswd file

4 releases (2 breaking)

0.3.0 Feb 17, 2023
0.2.1 Oct 30, 2021
0.2.0 Jul 19, 2021
0.1.0 Nov 1, 2019

#2478 in Cryptography

Download history 101/week @ 2024-07-26 65/week @ 2024-08-02 87/week @ 2024-08-09 29/week @ 2024-08-16 2/week @ 2024-08-23 10/week @ 2024-08-30 29/week @ 2024-09-06 6/week @ 2024-09-13 55/week @ 2024-09-20 128/week @ 2024-09-27 149/week @ 2024-10-04 89/week @ 2024-10-11 73/week @ 2024-10-18 48/week @ 2024-10-25 76/week @ 2024-11-01 280/week @ 2024-11-08

486 downloads per month
Used in rustic_server

Apache-2.0

23KB
450 lines

htpasswd-verify

Verify apache's htpasswd file

Supports MD5, BCrypt, SHA1, Unix crypt

Examples

Verify MD5 hash

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

It also allows to encrypt with md5 (not the actual md5, but the apache specific md5 that htpasswd file uses)

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:

Verify apache's htpasswd file

Supports MD5, BCrypt, SHA1, Unix crypt

Examples

Verify MD5 hash

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

Create [Htpasswd] without borrowing the data

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

It also allows to encrypt with md5 (not the actual md5, but the apache specific md5 that htpasswd file uses)

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/");

Dependencies

~5MB
~74K SLoC