


How to randomly generate a certain number of passwords using javascript
Jan 15, 2018 am 11:37 AMThis article mainly introduces you to the relevant information on how to use javascript to randomly generate a certain number of passwords. The article gives detailed js sample code, which is of certain significance to your study or work. Reference learning value, friends who are interested in JavaScript, please follow the editor to learn together.
Preface
This article mainly introduces the relevant content about using javascript to randomly generate a certain number of passwords, and shares it for your reference and study. , not much to say below, let’s take a look at the detailed introduction.
Requirements
Randomly generate a certain number of passwords. There is a minimum number and a maximum number. It must contain numbers, uppercase and lowercase letters, and special characters such as (- _ #);
code
function createPassword(min,max) { //可以生成随机密码的相关数组 var num = ["0","1","2","3","4","5","6","7","8","9"]; var english = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]; var ENGLISH = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]; var special = ["-","_","#"]; var config = num.concat(english).concat(ENGLISH).concat(special); //先放入一个必须存在的 var arr = []; arr.push(getOne(num)); arr.push(getOne(english)); arr.push(getOne(ENGLISH)); arr.push(getOne(special)); //获取需要生成的长度 var len = min + Math.floor(Math.random()*(max-min+1)); for(var i=4; i<len; i++){ //从数组里面抽出一个 arr.push(config[Math.floor(Math.random()*config.length)]); } //乱序 var newArr = []; for(var j=0; j<len; j++){ newArr.push(arr.splice(Math.random()*arr.length,1)[0]); } //随机从数组中抽出一个数值 function getOne(arr) { return arr[Math.floor(Math.random()*arr.length)]; } return newArr.join(""); }
use
Pass in the minimum number of digits and the maximum number of digits in a generated password to return a random password
console.log(createPassword(8,15));
The above is all the content of this article, I hope Provide help for everyone's learning.
Related recommendations:
Javascript converts the absolute path of the image into base64 encoding
Javascript implements a progress bar based on a timer Function example
Detailed explanation of multiple inheritance examples using JavaScript
The above is the detailed content of How to randomly generate a certain number of passwords using javascript. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to implement an online speech recognition system using WebSocket and JavaScript

Recommended: Excellent JS open source face detection and recognition project

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts

What to do if the word directory is generated incorrectly

How to use JavaScript and WebSocket to implement a real-time online ordering system
