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

#2 in #crypt

Download history 8817/week @ 2024-03-03 10377/week @ 2024-03-10 10729/week @ 2024-03-17 8871/week @ 2024-03-24 9923/week @ 2024-03-31 9221/week @ 2024-04-07 9648/week @ 2024-04-14 10196/week @ 2024-04-21 11866/week @ 2024-04-28 12152/week @ 2024-05-05 9863/week @ 2024-05-12 10866/week @ 2024-05-19 10186/week @ 2024-05-26 9733/week @ 2024-06-02 10580/week @ 2024-06-09 9301/week @ 2024-06-16

40,486 downloads per month
Used in 21 crates (15 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
~21K SLoC