atikin-password-generator
Version:
A simple and customizable password generator developed by: Atikin Verse.
28 lines (23 loc) • 956 B
JavaScript
/**
* Generates a random password.
* @param {number} length - Length of the password.
* @param {boolean} includeNumbers - Whether to include numbers.
* @param {boolean} includeSymbols - Whether to include symbols.
* @returns {string} - Generated password.
*/
function generatePassword(length = 12, includeNumbers = true, includeSymbols = true) {
const letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
const numbers = '0123456789';
const symbols = '!@#$%^&*()_+-=[]{}|;:",.<>?';
let characters = letters;
if (includeNumbers) characters += numbers;
if (includeSymbols) characters += symbols;
let password = '';
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * characters.length);
password += characters[randomIndex];
}
return password;
}
// Export the function for external usage
module.exports = generatePassword;