#password #hash #hashing #crypt

pwhash

A collection of password hashing routines in pure Rust

6 releases (1 stable)

1.0.0 Jan 3, 2021
0.3.1 Jul 8, 2020
0.3.0 Jan 13, 2019
0.2.0 May 9, 2018
0.1.1 Feb 9, 2016

#318 in Cryptography

Download history 1920/week @ 2022-06-12 3410/week @ 2022-06-19 4054/week @ 2022-06-26 3386/week @ 2022-07-03 3272/week @ 2022-07-10 3448/week @ 2022-07-17 3754/week @ 2022-07-24 4030/week @ 2022-07-31 3925/week @ 2022-08-07 3502/week @ 2022-08-14 4076/week @ 2022-08-21 4062/week @ 2022-08-28 3523/week @ 2022-09-04 4706/week @ 2022-09-11 3630/week @ 2022-09-18 4085/week @ 2022-09-25

16,091 downloads per month
Used in 16 crates (12 directly)

MIT license

105KB
1.5K SLoC

pwhash

A collection of password hashing and verification routines.

See the documentation for API reference.

Getting Started

Add the following to the [dependencies] section of your Cargo.toml:

pwhash = "1"

Example

use pwhash::bcrypt;

// Hash a password with default parameters.
let h_new = bcrypt::hash("password").unwrap();

// Verify a password against an existing hash.
let h = "$2y$05$bvIG6Nmid91Mu9RcmmWZfO\
         5HJIMCT8riNW0hEp8f6/FuA2/mHZFpe";
assert!(bcrypt::verify("password", h));

Summary

The following algorithms are currently implemented (in alphabetical order):

  • bcrypt

  • bsdi_crypt

  • md5_crypt

  • sha1_crypt

  • sha256_crypt

  • sha512_crypt

  • unix_crypt

Each algorithm resides in its eponymous module, and provides the following interface:

  • verify(): verify a password against a hash.

  • hash(): hash a password with default algorithm-spacific parameters.

  • hash_with(): hash a password with customized parameters.

There is also a convenience module unix which provides the functions unix::crypt, a crypt(3) work-alike, and unix::verify.

Dependencies

~1MB
~20K SLoC