Password Encryption
The password encryption module provides password encryption and hashing functionality to Boxlang.
Installation
# For Operating Systems using our Quick Installer
install-bx-module bx-password-encrypt
# Using CommandBox to install for web servers
box install bx-password-encryptBCrypt Hashing
Examples
// Hash a password with default cost factor (10)
hashedPassword = BCryptHash( "mySecurePassword123" );
// Hash with custom cost factor (higher = more secure but slower)
hashedPassword = BCryptHash( "mySecurePassword123", 12 );
// Verify a password
isValid = BCryptVerify( "mySecurePassword123", hashedPassword );
// Using in a user registration workflow
component {
function createUser( required string username, required string password ) {
var user = {
username: arguments.username,
passwordHash: BCryptHash( arguments.password )
};
// Save to database
queryExecute(
"INSERT INTO users (username, password_hash) VALUES (:username, :passwordHash)",
user
);
}
function authenticateUser( required string username, required string password ) {
var user = queryExecute(
"SELECT password_hash FROM users WHERE username = :username",
{ username: arguments.username },
{ returntype: "array" }
);
if( arrayLen( user ) && BCryptVerify( arguments.password, user[1].password_hash ) ) {
return true;
}
return false;
}
}Argon2 Hashing
Examples
SCrypt Hashing
Examples
PBKDF2 Key Derivation
Examples
Best Practices
GitHub Repository and Reporting Issues
Last updated
Was this helpful?
