• 🌙 Community Spirit

    Ramadan Mubarak! To honor this month, Crax has paused NSFW categories. Wishing you peace and growth!

Simple NodeJS password generator (1 Viewer)

Currently reading:
 Simple NodeJS password generator (1 Viewer)

Recently searched:

allwebtestbb

Member
LV
1
Joined
Aug 6, 2024
Threads
11
Likes
3
Awards
5
Credits
572©
Cash
0$
No additional packages needed

JavaScript:
// Password generator function
function generatePassword(length = 12, options = { lowercase: true, uppercase: true, numbers: true, symbols: true }) {
  // Define character sets
  const lowercase = 'abcdefghijklmnopqrstuvwxyz';
  const uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  const numbers = '0123456789';
  const symbols = '!@#$%^&*()_+[]{}|;:,.<>?';

  // Create a pool of characters based on the selected options
  let characters = '';
  if (options.lowercase) characters += lowercase;
  if (options.uppercase) characters += uppercase;
  if (options.numbers) characters += numbers;
  if (options.symbols) characters += symbols;

  // Generate the password
  let password = '';
  for (let i = 0; i < length; i++) {
    const randomIndex = Math.floor(Math.random() * characters.length);
    password += characters[randomIndex];
  }

  return password;
}

// Example usage: Generate a 16-character password with all character types
const password = generatePassword(16, { lowercase: true, uppercase: true, numbers: true, symbols: true });
console.log('Generated Password:', password);
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Tips
Recently searched:

Similar threads

Users who are viewing this thread

Top Bottom