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 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

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 :: javascript get max value in array of objects 
Javascript :: react tutorial app 
Javascript :: callback function jquery 
Javascript :: convert milliseconds to dd/mm/yyyy javascript 
Javascript :: javascript binary tree 
Javascript :: jquery textarea value 
Javascript :: classes in js 
Javascript :: dom traversal jquery 
Javascript :: && condition in javascript 
Javascript :: class in js 
Javascript :: loop js 
Javascript :: javascript link to page 
Javascript :: for-of loop 
Javascript :: animation js 
Javascript :: id multiple same property array combining 
Javascript :: shopify liquid logic 
Javascript :: remove equal objects in list of json js 
Javascript :: javascript undefined used with number, boolean or null 
Javascript :: javascript include too large or too small numbers 
Javascript :: javascript Skip Items 
Javascript :: post css nesting nuxt 
Javascript :: httpclient post raw json body 
Javascript :: Multiply string using a for loop 
Javascript :: theme ui with react 17 
Javascript :: link change page react 
Javascript :: phaser animation on update event 
Javascript :: reactjs doc error 
Javascript :: using lambda for elasticache node.js 
Javascript :: Return characters in a string in alphabetic order 
Javascript :: learn javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =