Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ jobs:
- uses: actions/checkout@v4
- name: Build
run: cargo build --release --verbose
- name: Run tests
- name: Publish
run: cargo publish --token ${{ secrets.TOKEN }}
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cas-lib"
version = "0.2.69"
version = "0.2.70"
edition = "2021"
description = "A function wrapper layer for RustCrypto and Dalek-Cryptography. Intended to be used in FFI situations with a global heap deallactor at the top level project."
license = "Apache-2.0"
Expand Down
9 changes: 9 additions & 0 deletions src/password_hashers/bcrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ use bcrypt::{hash, verify, DEFAULT_COST};
pub struct CASBCrypt;

impl CASBCrypt {
/// Hashes a password using bcrypt with a customized cost.
/// Parameters:
/// - password_to_hash: The password to be hashed.
/// - cost: The cost parameter for bcrypt (default is 12 and max is 31).
/// Returns the hashed password as a string.
pub fn hash_password_customized(password_to_hash: String, cost: u32) -> String {
return hash(password_to_hash, cost).unwrap();
}

/// Hashes a password using bcrypt.
/// Returns the hashed password as a string.
pub fn hash_password(password_to_hash: String) -> String {
Expand Down
8 changes: 7 additions & 1 deletion tests/password_hashers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,11 @@ mod password_hashers {
assert_eq!(true, verification);
}


#[test]
pub fn bcrypt_hash_password_customized() {
let password = "DoNotUseThisPassword".to_string();
let hash = CASBCrypt::hash_password_customized(password.clone(), 12);
let verification = CASBCrypt::verify_password(hash, password);
assert_eq!(true, verification);
}
}