laraship
Version:
Set sail with Laravel - Docker environment generator for Laravel projects
21 lines (17 loc) • 830 B
JavaScript
function generateStrongPassword() {
const length = 16;
const charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
let password = '';
// Ensure at least one of each character type
password += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[Math.floor(Math.random() * 26)]; // Uppercase
password += 'abcdefghijklmnopqrstuvwxyz'[Math.floor(Math.random() * 26)]; // Lowercase
password += '0123456789'[Math.floor(Math.random() * 10)]; // Number
password += '_';
// Fill the rest randomly
for (let i = password.length; i < length; i++) {
password += charset[Math.floor(Math.random() * charset.length)];
}
// Shuffle the password
return password.split('').sort(() => Math.random() - 0.5).join('');
}
module.exports = { generateStrongPassword };