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

#638 in Cryptography

Download history 5232/week @ 2024-12-21 6315/week @ 2024-12-28 16394/week @ 2025-01-04 18615/week @ 2025-01-11 17998/week @ 2025-01-18 20610/week @ 2025-01-25 18574/week @ 2025-02-01 17295/week @ 2025-02-08 18158/week @ 2025-02-15 18294/week @ 2025-02-22 18770/week @ 2025-03-01 18539/week @ 2025-03-08 20666/week @ 2025-03-15 18318/week @ 2025-03-22 19256/week @ 2025-03-29 19250/week @ 2025-04-05

81,152 downloads per month
Used in 23 crates (16 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

~1.5MB
~30K SLoC