Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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));
Comment

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('');  
  }    
    
};
Comment

Javascript random password generator Exampe

/**
 * Get Auto Generated Random Password
 * 
 * @param   int     length, eg: Default Length = 10
 * 
 * @return  string  Auto generated random password
 */
const getAutoGeneratedPassword = (length = 10) => {
    const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
          genPass = "";

    for (let i = 0, n = charset.length; i < length; ++i) {
        genPass += charset.charAt(Math.floor(Math.random() * n));
    }

    return genPass;
}
Comment

js password generator

const generateRandomPassword = () => {
    return Array(15) //password length
      .fill(
        "0123456789abcdefghijklmnopqrstuvwxyz!@#$%^&*()ABCDEFGHIJKLMNOPQRSTUVWXYZ"
      )
      .map(function (x) {
        const pwd = Math.floor(Math.random() * x.length);
        return x.substring(pwd, pwd + 1);
      })
      .join("");
  };

console.log(generateRandomPassword()) //'XX)PUMqA1mpDtZQ'
Comment

javascript password generator

Math.random()                        // Generate random number, eg: 0.123456
             .toString(36)           // Convert  to base-36 : "0.4fzyo82mvyr"
                          .slice(-8);// Cut off last 8 characters : "yo82mvyr"
Comment

random password generator javascript

let random = Math.floor(Math.random() * 8)
let numorabc = Math.floor(Math.random() * 2)
let random1 = Math.floor(Math.random() * 8)
let random2 = Math.floor(Math.random() * 8)
let random3 = Math.floor(Math.random() * 8)
let random4 = Math.floor(Math.random() * 8)
let random5 = Math.floor(Math.random() * 8)
let random6 = Math.floor(Math.random() * 8)
let random7 = Math.floor(Math.random() * 8)
let lastrandom = Math.floor(Math.random() * 5)



let numbers = ['1','2','3','4','5','6','7','8']
let abc = ['a','b','c','d','e','f','g','p']

let abc1 = abc[random1]
let abc2 = abc[random2]
let abc3 = abc[random3]
let num1 = numbers[random4]
let num2 = numbers[random5]
let num3 = numbers[random6]
let num5 = numbers[random7]

console.log(num3,abc1,num1,abc3,num2,num5)

if(lastrandom = 0){
        console.log(num3,num2,num1,abc1,abc2,abc3)
}else if(lastrandom = 1){
        console.log(abc1,num1,num2,abc2,num5,abc3)
}else if(lastrandom = 2){
        console.log(num1,abc1,num2,abc3,abc2)
}else if(lastrandom = 3){
        console.log(abc1,num1,abc2,num3,abc3,num5)
}else if(lastrandom = 4){
        console.log(abc1,abc2,num2,num3,abc3,num5)
}

Comment

javascript password generator

<input type='text' id='p'/><br/>
<input type='button' value ='generate' onclick='document.getElementById("p").value = Password.generate(16)'>
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to convert json result into datatable c# 
Javascript :: vue js reload page 
Javascript :: getx arguments 
Javascript :: convert date to string format dd/mm/yyyy javascript 
Javascript :: exit from fullscreen 
Javascript :: get placeholder innerhtml 
Javascript :: js generate random color 
Javascript :: moment timezone get timezone offset 
Javascript :: js write and get cookie 
Javascript :: get first element by class name jquery 
Javascript :: nodejs date difference 
Javascript :: nuxt looks for npm_modules on express 
Javascript :: check if function javascript 
Javascript :: Sending an Ajax request before form submit 
Javascript :: pagination hook react 
Javascript :: lexical scoping javascript 
Javascript :: on mouse not over jquiery 
Javascript :: javascript remove object property 
Javascript :: remove an element from an array javascript 
Javascript :: pyspark json multiline 
Javascript :: first and last char vowel reg exp same char 
Javascript :: ionic cordova icon notification 
Javascript :: moment get weekday name 
Javascript :: how to change attribute link in javascript 
Javascript :: angular show time ago 
Javascript :: open modal in jqwuery 
Javascript :: jquery option selected 
Javascript :: render tab screen when goBack function is called of other screen 
Javascript :: how to get the integer part of a string in javascript 
Javascript :: how to stop browser back js 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =