// Function to generate a random password of specified length
function generateRandomPassword(length) {
const charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*';
let password = '';
// Loop to randomly select characters from the charset
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * charset.length);
password += charset[randomIndex];
}
return password;
}
// Usage: Generate a random password with a length of 12
let randomPassword = generateRandomPassword(12);Generate Random Password in JavaScript
javascript
Related Posts
More content you might like
Code
javascript python +1
Generate Random Password
No preview available for this content.
Jan 26, 2024
Read MoreDiscussion 0
Please sign in to join the discussion.
No comments yet. Be the first to share your thoughts!