• Join CraxPro and earn real money through our Credit Rewards System. Participate and redeem credits for Bitcoin/USDT. Start earning today!
    Read the detailed thread here

Simple NodeJS password generator

Currently reading:
 Simple NodeJS password generator

allwebtestbb

Member
LV
0
Joined
Aug 6, 2024
Threads
5
Likes
0
Awards
1
Credits
330©
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

Similar threads

Top Bottom