Crate sha_crypt

Crate sha_crypt 

Source
Expand description

§RustCrypto: SHA-crypt password hash

crate Docs Build Status Apache2/MIT licensed Rust Version Project Chat

Pure Rust implementation of the SHA-crypt password hash based on SHA-256/SHA-512, a legacy password hashing scheme supported by the POSIX crypt C library.

Password hashes using this algorithm start with $5$ or $6$ when encoded using the Modular Crypt Format.

§License

Licensed under either of:

at your option.

§Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

§Usage

// NOTE: example requires `getrandom` feature is enabled

use sha_crypt::{PasswordHasher, PasswordVerifier, ShaCrypt};

let sha_crypt = ShaCrypt::default(); // default is SHA-512-crypt
let password = b"pleaseletmein"; // don't actually use this as a password!
let password_hash = sha_crypt.hash_password(password)?;
assert!(password_hash.as_str().starts_with("$6$"));

// verify password is correct for the given hash
sha_crypt.verify_password(password, &password_hash)?;

Re-exports§

pub use password_hash;password-hash

Structs§

Params
Algorithm parameters.
PasswordHashpassword-hash
Password hash encoded in the Modular Crypt Format (MCF). Owned form with builder functionality.
PasswordHashRefpassword-hash
Password hash reference type for hashes encoded in the Modular Crypt Format (MCF), e.g. $<id>$....
ShaCryptpassword-hash
SHA-crypt type for use with the PasswordHasher and PasswordVerifier traits, which can produce and verify password hashes in Modular Crypt Format.

Enums§

Algorithmpassword-hash
SHA-crypt algorithm variants: SHA-256 or SHA-512.
Error
Error type.

Constants§

BLOCK_SIZE_SHA256
Block size for SHA-256-crypt.
BLOCK_SIZE_SHA512
Block size for SHA-512-crypt.

Traits§

CustomizedPasswordHasherpassword-hash
Trait for password hashing functions which support customization.
PasswordHasherpassword-hash
High-level trait for password hashing functions.
PasswordVerifierpassword-hash
Trait for password verification.

Functions§

sha256_crypt
The SHA-256-crypt function which outputs a uniformly random byte array.
sha512_crypt
The SHA-512-crypt function which outputs a uniformly random byte array.

Type Aliases§

Result
Result type for the sha-crypt crate with its Error type.