Answers for "password generator in javascript"

5

javascript password generator example

function generatePassword(passwordLength) {
  var numberChars = "0123456789";
  var upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  var lowerChars = "abcdefghijklmnopqrstuvwxyz";
  var allChars = numberChars + upperChars + lowerChars;
  var randPasswordArray = Array(passwordLength);
  randPasswordArray[0] = numberChars;
  randPasswordArray[1] = upperChars;
  randPasswordArray[2] = lowerChars;
  randPasswordArray = randPasswordArray.fill(allChars, 3);
  return shuffleArray(randPasswordArray.map(function(x) { return x[Math.floor(Math.random() * x.length)] })).join('');
}

function shuffleArray(array) {
  for (var i = array.length - 1; i > 0; i--) {
    var j = Math.floor(Math.random() * (i + 1));
    var temp = array[i];
    array[i] = array[j];
    array[j] = temp;
  }
  return array;
}

alert(generatePassword(12));
Posted by: Guest on January-14-2020
5

javascript password generator

var Password = {
 
  _pattern : /[a-zA-Z0-9_\-\+\.]/,
  
  
  _getRandomByte : function()
  {
    // http://caniuse.com/#feat=getrandomvalues
    if(window.crypto && window.crypto.getRandomValues) 
    {
      var result = new Uint8Array(1);
      window.crypto.getRandomValues(result);
      return result[0];
    }
    else if(window.msCrypto && window.msCrypto.getRandomValues) 
    {
      var result = new Uint8Array(1);
      window.msCrypto.getRandomValues(result);
      return result[0];
    }
    else
    {
      return Math.floor(Math.random() * 256);
    }
  },
  
  generate : function(length)
  {
    return Array.apply(null, {'length': length})
      .map(function()
      {
        var result;
        while(true) 
        {
          result = String.fromCharCode(this._getRandomByte());
          if(this._pattern.test(result))
          {
            return result;
          }
        }        
      }, this)
      .join('');  
  }    
    
};
Posted by: Guest on July-26-2020
1

JavaScript Password Generator

/*
    This code comes from Vincent Lab
    And it has a video version linked here: https://www.youtube.com/watch?v=PtnYuiIyqeM
*/

function generate() {

    let password = "";

    let length = +document.getElementById("length").value;

    let lowerCase = document.getElementById("lowercase").checked;
    let upperCase = document.getElementById("uppercase").checked;
    let symbol = document.getElementById("symbols").checked;
    let number = document.getElementById("numbers").checked;

    if (lowerCase + upperCase + symbol + number <= 0)
        return;

    for (let i = 0; i < length; i++) {

        const r = generater(0, 3);
        if (lowerCase && r === 0) {
            password += generateRandomLowerCase();
        } else if (upperCase && r === 1) {
            password += generateRandomUpperCase();
        } else if (symbol && r === 2) {
            password += generateRandomSymbol();
        } else if (number && r === 3) {
            password += generater(0, 9);
        } else {
            i--;
        }

    }

    document.getElementById("result").textContent = password;

}

generate();

function generateRandomLowerCase() {
    return String.fromCharCode(generater(97, 122));
}

function generateRandomUpperCase() {
    return String.fromCharCode(generater(65, 90));
}

function generateRandomSymbol() {
    const symbols = "~*$%@#^&!?*'-=/,.{}()[]<>";
    return symbols[generater(0, symbols.length - 1)];
}

function generater(min = 0, max = 1) {
    return Math.floor(Math.random() * (max + 1 - min) + min);
}
Posted by: Guest on April-20-2021
-1

password generator javascript

const Numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
  const Names = ["Aaran", "Aaren", "Aodeba","Zaid", "Zain", "Zaine", "Zaineddine", "Zainedin", "Zak", "Zakaria", "Zakariya", "Zakary", "Zaki", "Zakir", "Zakk", "Zamaar", "Zander", "Zane", "Zarran", "Zayd", "Zayn", "Zayne", "Ze", "Zechariah", "Zeek", "Zeeshan", "Zeid", "Zein", "Zen", "Zendel", "Zenith", "Zennon", "Zeph", "Zerah", "Zhen", "Zhi", "Zhong", "Zhuo", "Zi", "Zidane", "Zijie", "Zinedine", "Zion", "Zishan", "Ziya", "Ziyaan", "Zohaib", "Zohair", "Zoubaeir", "Zubair", "Zubayr", "Zuriel"]
  const Symbols = ["#", "£", "@", "%", "?", "!", "+", "$", "-", "*"]
  const RandomName = Names[Math.floor(Math.random() * Names.length)];
  const RandomNumber = Numbers[Math.floor(Math.random() * Numbers.length)];
  const RandomNumber2 = Numbers[Math.floor(Math.random() * Numbers.length)];
  const RandomSymbol = Symbols[Math.floor(Math.random() * Symbols.length)];
  const RandomSymbol2 = Symbols[Math.floor(Math.random() * Symbols.length)];
  const RandomSymbol3 = Symbols[Math.floor(Math.random() * Symbols.length)];
  const RandomSymbol4 = Symbols[Math.floor(Math.random() * Symbols.length)];
  const Password = `${RandomNumber2}${RandomSymbol}${RandomName}${RandomNumber}${RandomSymbol4}`
  const Password2 = `${RandomNumber2}${RandomSymbol2}${RandomName}${RandomSymbol3}${RandomSymbol4}`
  const Password3 = `${RandomNumber}${RandomNumber2}${RandomName}${RandomNumber}${RandomSymbol4}`
  const Password4 = `${RandomSymbol2}${RandomSymbol3}${RandomName}${RandomNumber2}${RandomNumber}`
  const Passwords = [Password, Password2, Password3, Password4]
  const GeneratedPassword = Passwords[Math.floor(Math.random() * Passwords.length)];
  const GeneratedPasswordToLowerCase = GeneratedPassword.toLowerCase()
  /* Print The Passwords*/
  console.log(GeneratedPassword)
  console.log(GeneratedPasswordToLowerCase)
Posted by: Guest on June-12-2021
-2

javascript password generator

<input type='text' id='p'/><br/>
<input type='button' value ='generate' onclick='document.getElementById("p").value = Password.generate(16)'>
Posted by: Guest on July-26-2020

Code answers related to "password generator in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language