🔑 rscrypt
The Rscrypt library provides functionality for creating and verifying password hashes.
🚀 Installation
To use the rscrypt library in your Rust project, add it as a dependency in your Cargo.toml file:
[]
= "*"
Then, run cargo build to download and compile the dependencies.
Alternatively, you can use the following command for adding the latest version of the library:
cargo add rscrypt
Once installed, you can import the library in your Rust code using:
use ;
That's it! You're ready to use the rscrypt library in your Rust project.
🏗️ Struct Rscrypt
This struct provides the following utility functions:
🔎 Function compare(src: &str, dst: &str) -> bool
This function compares the plaintext password string src with the hashed password string dst. It returns true if they match, else false.
use ;
let salt = gen_salt;
let hashed = hash;
assert!;
🔒 Function gen_salt(cost: usize) -> String
This function generates a random salt value that can be used for hashing a password. The cost argument determines the number of computational rounds to perform during hashing.
use ;
let salt = gen_salt;
let hashed = hash;
assert!;
🔍 Function get_salt(hash: &str) -> Option<String>
This function extracts the salt value used for hashing from the given hash string.
use ;
let hash = "iIBDWiEk0118e29VbozxVmoCscUzu6k05cKGFbtgogI=$rscrypt$0.2.0$10$rLBARHBrWKCsvACVvBAN7O";
let salt = get_salt;
assert_eq!;
🚀 Function hash(salt: &str, unhashed_str: &str) -> String
This function hashes the plaintext password string unhashed_str with the given salt value salt.
use ;
let hashed = hash;
assert_eq!;
🕵️♀️ Function is_valid_hash(hash: &str) -> bool
This function returns true if the given hash string is a valid hashed password string, else false.
use ;
let hash = "iIBDWiEk0118e29VbozxVmoCscUzu6k05cKGFbtgogI=$rscrypt$0.2.0$10$rLBARHBrWKCsvACVvBAN7O";
assert!;
📝 License
This project is licensed under the MIT License.