https://github.com/mberry/bcrypter
Bcrypt in Rust.
https://github.com/mberry/bcrypter
bcrypt cryptography hashing passwords
Last synced: 9 months ago
JSON representation
Bcrypt in Rust.
- Host: GitHub
- URL: https://github.com/mberry/bcrypter
- Owner: mberry
- License: apache-2.0
- Created: 2018-10-19T06:27:37.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-01-18T16:45:11.000Z (over 5 years ago)
- Last Synced: 2025-08-13T07:40:01.554Z (11 months ago)
- Topics: bcrypt, cryptography, hashing, passwords
- Language: Rust
- Homepage:
- Size: 71.3 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: License-Apache.md
Awesome Lists containing this project
README
# BCrypter
[](https://crates.io/crates/bcrypter) [](https://travis-ci.com/MitchellBerry/BCrypter) 
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](https://docs.rs/crate/bcrypter)
## Installation
In your Cargo.toml file:
```toml
[dependencies]
bcrypter = "0.1.1"
```
## Usage
#### Basic hash
```rust
extern crate bcrypter;
use bcrypter::password;
let pw = "hunter2".to_string();
let bcrypt_hash = password(pw).hash().unwrap();
```
#### Custom cost
```rust
let result = password(pw)
.cost(6)
.hash()
.unwrap();
```
#### Custom salt
```rust
let salt = [0u8; 16];
let result = password(pw)
.salt(salt)
.cost(8)
.hash()
.unwrap();
```
#### Verify password
```rust
let known_hash = "$2a$04$7eAf8viXin8zazyvaU2HLuZGEbvaHy/lsnlG.HFWkBST5irHhXKJO".to_string();
let correct_password : bool = password(pw)
.verify(known_hash)
.unwrap()
```
#### Raw digest
```rust
let result = password(pw).hash().unwrap();
let digest_bytes : [u8: 24] = result.digest;
```
#### Notes
* 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.