[][src]Module pwhash::sha256_crypt

SHA-256 based hash.

This algorithm was developed as an alternative to bcrypt with NIST-approved hashing functions. It is similar to MD5-crypt, but has a variable number of rounds and a larger salt.

Example

use pwhash::sha256_crypt;

let h = "$5$rounds=11858$WH1ABM5sKhxbkgCK$\
         aTQsjPkz0rBsH3lQlJxw9HDTDXPKBxC0LlVeV69P.t1";
assert_eq!(sha256_crypt::hash_with(h, "test").unwrap(), h);

Parameters

  • Password length: unlimited.

  • Salt length: 0 to 16 characters. Default is 16.

  • Rounds: 1000 to 999999999. Default is 5000. If a number outside of the range is chosen, it is coerced to the nearest limit.

Hash Format

The format of the hash is $5$rounds={rounds}${salt}${checksum}, where:

  • {rounds} is the number of rounds, encoded as a decimal number without leading zeroes.

  • {salt} is the salt string.

  • {checksum} is a 43-character Base64 encoding of the checksum.

The format $5${salt}${checksum} can be used if the default number of rounds is chosen.

Constants

DEFAULT_ROUNDS

Default number of rounds.

MAX_ROUNDS

Maximum rounds.

MAX_SALT_LEN

Maximum (and default) salt length.

MIN_ROUNDS

Minimum rounds.

Functions

hashDeprecated

Hash a password with a randomly generated salt and the default number of rounds.

hash_withDeprecated

Hash a password with user-provided parameters.

verify

Verify that the hash corresponds to a password.