JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html>
<head>
<title>Password Generator</title>
</head>
<body>
<button onclick="fnclick()">Generate Password</button>
</body>
</html>
JavaScript
/*start : get user data and verify user input
=====================================*/
function fnprompt(){
return prompt("Please enter numeric between 4 to 100.");
}
function rangecheck(value){
if(value >= 4 && value <= 100)
return value;
else
return 0;
}
var passlength = 0;
var temppass = "";
function fninit(){
do{
passlength = rangecheck(fnprompt());
}while(passlength === 0);
}
/*end : get user data and verify user input
=====================================*/
/*start : set password pattern according password length.
=====================================*/
//random upper case or lower case alphabet
function fnalphabet(){
var alphabet = String.fromCharCode(Math.floor((Math.random() * (90-65)) + 65));
var lower = Math.random() >= 0.5;
if(lower)
return alphabet.toLowerCase();
else
return alphabet.toUpperCase();
}
//create random numeric
function fnnumeric(){
return String.fromCharCode(Math.floor((Math.random() * (57-48)) + 48));
}
//create special character
function fnspecial(){
var possible = "!@#$%^&*()";
return possible.charAt(Math.floor(Math.random() * possible.length));
}
function fnencodetype(value){
switch(value){
case 1:
return fnalphabet();
break;
case 2:
return fnnumeric();
break;
default:
return fnspecial();
}
}
function fncreate(){
for(var i=1; i<=passlength; i++){
if(i == 1) temppass += fnencodetype(1);
else if(i == 2) temppass += fnencodetype(2);
else if(i == 3) temppass += fnencodetype(3);
else
temppass += fnencodetype(Math.floor((Math.random() * 3) + 1));
}
}
/*end : set password pattern according password length.
=====================================*/
/* start:file will be download after password generated
==================================*/
function fngenerate(){
var content = temppass;
if (confirm("password is:...