javascript password generator

Solutions on MaxInterview for javascript password generator by the best coders in the world

showing results for - "javascript password generator"
Caterina
29 Mar 2018
1function generatePassword(passwordLength) {
2  var numberChars = "0123456789";
3  var upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
4  var lowerChars = "abcdefghijklmnopqrstuvwxyz";
5  var allChars = numberChars + upperChars + lowerChars;
6  var randPasswordArray = Array(passwordLength);
7  randPasswordArray[0] = numberChars;
8  randPasswordArray[1] = upperChars;
9  randPasswordArray[2] = lowerChars;
10  randPasswordArray = randPasswordArray.fill(allChars, 3);
11  return shuffleArray(randPasswordArray.map(function(x) { return x[Math.floor(Math.random() * x.length)] })).join('');
12}
13
14function shuffleArray(array) {
15  for (var i = array.length - 1; i > 0; i--) {
16    var j = Math.floor(Math.random() * (i + 1));
17    var temp = array[i];
18    array[i] = array[j];
19    array[j] = temp;
20  }
21  return array;
22}
23
24alert(generatePassword(12));
Máximo
23 May 2016
1var Password = {
2 
3  _pattern : /[a-zA-Z0-9_\-\+\.]/,
4  
5  
6  _getRandomByte : function()
7  {
8    // http://caniuse.com/#feat=getrandomvalues
9    if(window.crypto && window.crypto.getRandomValues) 
10    {
11      var result = new Uint8Array(1);
12      window.crypto.getRandomValues(result);
13      return result[0];
14    }
15    else if(window.msCrypto && window.msCrypto.getRandomValues) 
16    {
17      var result = new Uint8Array(1);
18      window.msCrypto.getRandomValues(result);
19      return result[0];
20    }
21    else
22    {
23      return Math.floor(Math.random() * 256);
24    }
25  },
26  
27  generate : function(length)
28  {
29    return Array.apply(null, {'length': length})
30      .map(function()
31      {
32        var result;
33        while(true) 
34        {
35          result = String.fromCharCode(this._getRandomByte());
36          if(this._pattern.test(result))
37          {
38            return result;
39          }
40        }        
41      }, this)
42      .join('');  
43  }    
44    
45};
Mika
21 Mar 2020
1/*
2    This code comes from Vincent Lab
3    And it has a video version linked here: https://www.youtube.com/watch?v=PtnYuiIyqeM
4*/
5
6function generate() {
7
8    let password = "";
9
10    let length = +document.getElementById("length").value;
11
12    let lowerCase = document.getElementById("lowercase").checked;
13    let upperCase = document.getElementById("uppercase").checked;
14    let symbol = document.getElementById("symbols").checked;
15    let number = document.getElementById("numbers").checked;
16
17    if (lowerCase + upperCase + symbol + number <= 0)
18        return;
19
20    for (let i = 0; i < length; i++) {
21
22        const r = generater(0, 3);
23        if (lowerCase && r === 0) {
24            password += generateRandomLowerCase();
25        } else if (upperCase && r === 1) {
26            password += generateRandomUpperCase();
27        } else if (symbol && r === 2) {
28            password += generateRandomSymbol();
29        } else if (number && r === 3) {
30            password += generater(0, 9);
31        } else {
32            i--;
33        }
34
35    }
36
37    document.getElementById("result").textContent = password;
38
39}
40
41generate();
42
43function generateRandomLowerCase() {
44    return String.fromCharCode(generater(97, 122));
45}
46
47function generateRandomUpperCase() {
48    return String.fromCharCode(generater(65, 90));
49}
50
51function generateRandomSymbol() {
52    const symbols = "~*$%@#^&!?*'-=/,.{}()[]<>";
53    return symbols[generater(0, symbols.length - 1)];
54}
55
56function generater(min = 0, max = 1) {
57    return Math.floor(Math.random() * (max + 1 - min) + min);
58}
Martin
17 Jun 2017
1 const Numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
2  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"]
3  const Symbols = ["#", "£", "@", "%", "?", "!", "+", "$", "-", "*"]
4  const RandomName = Names[Math.floor(Math.random() * Names.length)];
5  const RandomNumber = Numbers[Math.floor(Math.random() * Numbers.length)];
6  const RandomNumber2 = Numbers[Math.floor(Math.random() * Numbers.length)];
7  const RandomSymbol = Symbols[Math.floor(Math.random() * Symbols.length)];
8  const RandomSymbol2 = Symbols[Math.floor(Math.random() * Symbols.length)];
9  const RandomSymbol3 = Symbols[Math.floor(Math.random() * Symbols.length)];
10  const RandomSymbol4 = Symbols[Math.floor(Math.random() * Symbols.length)];
11  const Password = `${RandomNumber2}${RandomSymbol}${RandomName}${RandomNumber}${RandomSymbol4}`
12  const Password2 = `${RandomNumber2}${RandomSymbol2}${RandomName}${RandomSymbol3}${RandomSymbol4}`
13  const Password3 = `${RandomNumber}${RandomNumber2}${RandomName}${RandomNumber}${RandomSymbol4}`
14  const Password4 = `${RandomSymbol2}${RandomSymbol3}${RandomName}${RandomNumber2}${RandomNumber}`
15  const Passwords = [Password, Password2, Password3, Password4]
16  const GeneratedPassword = Passwords[Math.floor(Math.random() * Passwords.length)];
17  const GeneratedPasswordToLowerCase = GeneratedPassword.toLowerCase()
18  /* Print The Passwords*/
19  console.log(GeneratedPassword)
20  console.log(GeneratedPasswordToLowerCase)
Violeta
27 Jun 2017
1function getpass() {
2    var chars = "0123456789~!@#$%^&*()_+}{[]|abcdefghikjlmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
3    var pass = "";
4    var passLength = 16;
5    for (var i = 0; i < passLength; i++) {
6        var randPass = Math.floor(Math.random() * chars.length);
7        pass += chars.substring(randPass, randPass+1);
8    }
9    document.getElementById('strong_pass').value = pass;
10}
11function copyToClipboard() {
12    var copyText = document.getElementById('strong_pass');
13    var copyPass = document.getElementById('strong_pass').value;
14    var fa_iocn = document.getElementsByClassName('fa');
15    if (copyPass == "") {
16        alert("Please Generate Password");
17    }else {
18        $(fa_iocn).removeClass("fa-copy");
19        $(fa_iocn).addClass("fa-check");
20        $("#strong_pass").addClass("focus_success");
21        alert("Password Copied Successfully")
22    }
23    copyText.select();
24    copyText.setSelectionRange(0, 99999);
25    document.execCommand("copy");
26}
27$(".strong_pass_generator #generatorbutton").click(function(){
28    $(".strong_pass_generator i").removeClass("fa-check");
29    $(".strong_pass_generator i").addClass("fa-copy");
30});
Michele
16 Mar 2017
1<input type='text' id='p'/><br/>
2<input type='button' value ='generate' onclick='document.getElementById("p").value = Password.generate(16)'>
queries leading to this page
javascript password generator npmgenerate automatic password javascriptjavascript generate password functionrandom password generator jsjs randomly generate a password that meets certain criteriagenerate password in javascriptauto generate password jquery with one upper case lowercase and special charterunique password javascriptjs random password generatorprompt for password generator javascriptpassword genarator by jspassword genarator javascriptpassword function generator jsjs generate random passwordwrite js code to make random password generatorhow to start a password genertor in javascriptgenrate random password in jsfor loops for password generatorn javascriptcreate password generator javascriptrandom characters prefills password stackoverflow reactpassword generator in javascripthow to create password generator in javascriptjavascript generate complex passwordjavacript logic password generatorgenerate 10 character password jquerygenerator strong password jspassword generator java scriptpassword generator algorithm javascriptjavascript password generatojscriot generate password from certain carshow to make a password generator in javascript with upper and lowerpassword generator with javascriptpassword generator in javascript coderadom password jsrandom password generator in c 23nodejs password generate numbers onlyhow to create a password generator with javascriptpassword generator javascrptjavascript variable betwen 8 and 128 characterspassword generator js confirmjavascript random password generator sinplei want to generate password in javascriptjavascript generate a passwordpassword generator with specific length jsjs password generatorgenerate random password stackoverflow javascriptrandom password generator javascriptcreate password generator javascript errorpassword generator on jalgorithm for password generator jsfunction that create a password with the length of the parameter in javascripthow to make a random password generator in javascriptcommon password generator jsjavascript generate password stringhow to create a password generator in javascriptpassword generator javascript simplehtml and js password generatorsecure password generator jshow do you write a for loop in javascript for password generatorgeneratore password javascripthow to generate 8 character password in jshow to make a password generatorin javascripthow to create a random password generator in javascriptjavascript code for random password generatorpassword gen in jspassword with 8 characters in nodejsmaking a password generator in jspassword generator nodpe jsgenerate password jsbuild password generator with if statements javascriptpassword generator web app with javascriptlimit number of characters password generator jshow to create a password generator javascriptpassword generator javascript codegenerate password hash jspassword generator jsjavascript random password generator with timegeneratepassword 28 29 3b jsusing js to generate passwordcreate random password in javascriptangular random password generatorlogic behind password generator javascriptrandom password generator with javascriptgenerate random password jqueryrandom password jspassword generator in jsonline password generator javascriptjs generate random strong passwordjavascript password generator librarygeneratepassword 28 29 jshow to create a for loop for a password generator javascriptjavascript generate random passwordrandom password generator function javascriptpassword generator javascriptgenerate secure string password in nodejsjavascript password generator with special symbolageneratepassword 28 29 javascriptjavascript 2b password generatorjs auto generate passwords with regexpassword gen javascriptjquery password generatorjs function generator random passwordjavascript for loop password generator even distributionjs for password suggestionwhere to console log when generating random passwordsgenerate password javascript codegen password javascriptjs generate password stringauto generate password jquerygenerate 8 digit random password in javascriptjs generator passwordjavascript random password generator with rulesgenerate random and unique password javascriptpassword generator website jslist of special characters for javascript password generaterandom password generator javascript for ihow to make a password generator whit javascripttypescript random password generatorrandom password angularpassword generator and password strength using javascriptjavascript spa password creatormake password generator javascriptpassword generator js coderandom password genreator javasscriptcreate a simple password generator javascriptrandom password generator using jsrandom password javascriptjavascript 3a password generator3 random words password generator javascriptjavascript challenge password generatorpasswordgen 28num 29 jsjs password genhow to create a password generator using jspassword generator node jsgenerate temp password javascrtipwhat is password generator javascripthow to make a password generator in javascripthow to create a random password generator javascriptpassword generator in javascript setting minum lenghtpassword generator js libraryjavascript generate password with special charactersgeneraterandom password jsgenrate password function javascriptstrong password javascriptrandom password generator tutorial javascrpt alwys include special caharcetsjs secure password generatorjavascript password generator returning integerspassword generator javascript using confirm and promptgenerate random password with special characters javascrtipgetasecurerandompassword 28 29 javascripthow to auto generate password in javascriptcreating a password generator in javascriptstrong password generator javascriptjavascript password generator with rulescreate random password javascriptcreate a random password with map function javascriptgenerate random password vanilla jsmake a assword generator jsgenerate password javascriptrandom password generator character length javascriptcode for random password generator in javascriptjs generate passowrdbuild a password generator with javascript tutorialjavascript generate passwordpassword generator using javascriptjavascript password generator examplegenerate random password javascriptjavascript random password generator 5drandom password generator in jsjavascript password generator with if statementnode js random passwordhow to create a random password in javascripthow to create a password creator using javascriptmake method in javascript for password generatorauto generate password in javascriptjavascript random password generatorpassword list generator javascriptis it okay to make a password generator and store it using jsgenerate strong password javascriptgenerator of password script javascriptjavascript homework 3a password generatorvar randnum 3d math floor 28math random 28 29 2a chars length 29 3b password 3d password 2b chars 5brandnum 5d console log 28password 29plain javascript generate random passpassword generator javascript numberpassword generator steps in javascriptrandom password generator in javascriptjavascript for loop password generatorpassword generator in javascript without es6js generate passwordvanilla javascript multiple character array password generatorjavascript password generatorcreating a password generator javascriptpassword from word generator javascriptjavascript strong password generatorgenerate password with jsjavascript generate strong passwordjavascript password generator