Crates.io | bcrypter |
lib.rs | bcrypter |
version | 0.1.1 |
source | src |
created_at | 2018-10-20 03:01:29.122534 |
updated_at | 2018-10-20 03:20:50.242795 |
description | The bcrypt password hashing function in pure Rust. Supports no_std |
homepage | |
repository | https://github.com/MitchellBerry/BCrypter |
max_upload_size | |
id | 91611 |
size | 31,758 |
A pure rust implementation of the bcrypt hashing function based on the Blowfish cipher. Currently only running on nightly builds. Full API documentation can be found here
In your Cargo.toml file:
[dependencies]
bcrypter = "0.1.1"
extern crate bcrypter;
use bcrypter::password;
let pw = "hunter2".to_string();
let result = password(pw).hash().unwrap();
let bcrypt_hash_string = result.hash_string;
let result = password(pw)
.cost(6)
.hash()
.unwrap();
let salt = [0u8; 16];
let result = password(pw)
.salt(salt)
.cost(8)
.hash()
.unwrap();
let known_hash = "$2a$04$7eAf8viXin8zazyvaU2HLuZGEbvaHy/lsnlG.HFWkBST5irHhXKJO".to_string();
let correct_password : bool = password(pw)
.verify(known_hash)
.unwrap()
let result = password(pw).hash().unwrap();
let digest_bytes : [u8: 24] = result.digest;
The default cost is 12
A random 16 byte array is used when no salt parameter is provided.
The maximum password input is 72 bytes, anything over that will be truncated rather than raise an error. If you need larger inputs consider hashing it beforehand.