DeveloperBreeze

Generate Random Password in JavaScript

javascript
// 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);

Continue Reading

Discover more amazing content handpicked just for you

Code
php

PHP Generate Random Password

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript python +1

Generate Random Password

No preview available for this content.

Jan 26, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!