#bcrypt #password #hash


Easy password hashing (includes bcrypt)

4 releases

0.1.3 Nov 3, 2022
0.1.2 Aug 12, 2019
0.1.1 May 16, 2018
0.1.0 May 16, 2018

#425 in Cryptography

Download history 4/week @ 2022-08-12 4/week @ 2022-08-19 4/week @ 2022-08-26 4/week @ 2022-09-02 16/week @ 2022-09-09 3/week @ 2022-09-16 1/week @ 2022-09-23 9/week @ 2022-09-30 5/week @ 2022-10-07 1/week @ 2022-10-14 3/week @ 2022-10-21 20/week @ 2022-10-28 20/week @ 2022-11-04 7/week @ 2022-11-11 6/week @ 2022-11-18 4/week @ 2022-11-25

52 downloads per month

MIT license

101 lines

Easy password hashing

Supported algorithms:

  • Bcrypt


Using Bcrypt as is results in passwords being limited to a length of 72. This means it's not easy to salt the password or support arbitrarily long user passwords.

This library performs a HMAC with SHA256 used as the hash function before feeding the result into Bcrypt. As such, any length of password can be used with Bcrypt when passwords are made or verified with this library.


Hashing a password:

extern crate easy_password;

use easy_password::bcrypt::hash_password;

let bcrypt_rounds = 12; // Secure default
let hash: String =
    hash_password("my_password", b"secure_key", 12).unwrap();

Verifying a hash:

extern crate easy_password;

use easy_password::bcrypt::hash_password;

let success: bool =
    verify_password("test_password", hash.as_str(), b"secure_key").unwrap();

Linting Code

Install clippy:

rustup component add clippy

To lint the code:

cargo clippy

Apply all suggested refactorings (don't forget to reformat code)

Formatting Code

Note: Currently the nightly version of rustfmt is used for formatting purposes only. The project itself is written and tested on the most current version of stable Rust.

To install rustfmt:

rustup component add rustfmt --toolchain nightly

To format the code:

cargo +nightly fmt


MIT License, see LICENSE


~19K SLoC