Password Encrypt
Encrypt Password
The encrypt
module provides a robust solution for encrypting passwords with customizable rules. It ensures that passwords adhere to specific criteria, enhancing security and mitigating common vulnerabilities.
Features
- Customizable Rules: Define rules for password encryption, including requirements for uppercase letters, lowercase letters, special characters, and numbers.
- Personal Information Check: Optionally prevent passwords from containing personal information such as the user's name, last name, or birth date.
- SHA-256 Hashing: Utilizes the SHA-256 hashing algorithm for secure password encryption.
- Error Handling: Throws descriptive errors when password validation fails, providing detailed feedback for improved debugging.
- Easy Integration: Seamlessly integrate the
encryptPassword
function into your Node.js applications to enhance password security effortlessly.
Usage
const { encrypt } = require('apiutils.js');
const plainTextPassword = 'myP@ssword123';
const rules = {
uppercase: true,
lowercase: true,
specialCharacters: true,
numbers: true,
containsPersonalInfo: true,
personalInfo: {
name: 'John',
last_name: 'Doe',
born_date: '1990-01-01'
}
};
try {
const hashedPassword = encrypt(plainTextPassword, rules);
console.log('Hashed Password:', hashedPassword);
} catch (error) {
console.error('Error:', error.message);
}
Parameters
plain_text
(string): The password to encrypt.rules
(object): An object containing rules for password encryption.uppercase
(boolean): Whether the password must contain at least one uppercase letter (default:true
).lowercase
(boolean): Whether the password must contain at least one lowercase letter (default:true
).specialCharacters
(boolean): Whether the password must contain at least one special character (default:true
).numbers
(boolean): Whether the password must contain at least one number (default:true
).containsPersonalInfo
(boolean): Whether the password must not contain any personal information (default:true
).personalInfo
(object): An object containing personal information to avoid in the password (required ifcontainsPersonalInfo
istrue
).name
(string): The user's first name.last_name
(string): The user's last name.born_date
(string): The user's birth date.
Return Value
- Returns the hashed password as a string.
Throws
- Throws an error if the password does not meet the specified criteria or contains personal information.