Crates.io | bcrypt-wasm |
lib.rs | bcrypt-wasm |
version | 0.7.0 |
source | src |
created_at | 2020-01-27 00:04:41.41171 |
updated_at | 2020-04-09 14:43:20.595276 |
description | Easily hash and verify passwords using bcrypt |
homepage | https://github.com/ATechnoHazard/rust-bcrypt |
repository | https://github.com/ATechnoHazard/rust-bcrypt |
max_upload_size | |
id | 202283 |
size | 36,177 |
Add the following to Cargo.toml:
bcrypt = "0.7"
The minimum Rust version is 1.34.0
The crate makes 3 things public: DEFAULT_COST
, hash
, verify
.
extern crate bcrypt;
use bcrypt::{DEFAULT_COST, hash, verify};
let hashed = hash("hunter2", DEFAULT_COST)?;
let valid = verify("hunter2", &hashed)?;
The cost needs to be an integer between 4 and 31 (see benchmarks to have an idea of the speed for each), the DEFAULT_COST
is 12.
Speed depends on the cost used: the highest the slowest. Here are some benchmarks on my 4 years old laptop to give you some ideas on the cost/speed ratio. Note that I don't go above 14 as it takes too long.
test bench_cost_4 ... bench: 1,197,414 ns/iter (+/- 112,856)
test bench_cost_10 ... bench: 73,629,975 ns/iter (+/- 4,439,106)
test bench_cost_default ... bench: 319,749,671 ns/iter (+/- 29,216,326)
test bench_cost_14 ... bench: 1,185,802,788 ns/iter (+/- 37,571,986)
This gist for the hash splitting and the null termination.
hash_with_salt
function and make Version::format_for_version
publicbcrypt
function + edition 2018?
and handle more errors