This article describes the JS password generation and strength detection methods. Share to everyone for your reference, specific as follows:
1. Generate Strong passwords
Screenshot below:
The relevant code is as follows:
function Getpwd (n)
{
var s = ';
while (n--)
s + + string.fromcharcode (+ Math.floor (Math.random () * (126-33)))
document.getElementById (' Txt1 '). Value = S;
}
2. Calculate Password cracking time
Screenshot below:
The relevant code is as follows:
function GetTime ()
{
var str = ' expected cracked: ';
var Selchar = document.getElementById (' Selchar ');
var Txtpwdlen = document.getElementById (' Txtpwdlen ');
var num = Math.pow (parseint (Selchar.value), parseint (Txtpwdlen.value));
str = formattime (num/(1024*1024*1024*2.4*2));
document.getElementById (' span2 '). InnerHTML = str;
function Formattime (s)
{
var str = ';
if (s<1) return ' less than 1 seconds! ';
s = Math.floor (s);
if (S >= 1) str = s% 60 + ' sec ' + str;
s = Math.floor (S/60);
if (S >= 1) str = s% 60 + ' min ' + str;
s = Math.floor (S/60);
if (S >= 1) str = s% 24 + ' when ' + str;
s = Math.floor (S/24);
if (S >= 1) str = s + ' Day ' + str;
return str;
}
3. Password Security detection
Screenshot below:
The relevant code is as follows:
function Showpwd () {var p = document.getElementById (' txt2 '). Value; if (P.length < 4) {ShowError (' password at least 4 bits!)
');
Return
var o = checkpwd (p); if (o.issame) {showerror (' password is a repeating character!)
');
Return for (var i=0 i<arrpwd.length; i++) {if (arrpwd[i] = = P | | arrpwd[i].indexof (P) = 0) {showerror (' secret Code is 100 big common password!
');
Return
} var year = parseint (P.substr (0,4));
if (!isnan (year) && year>1900 && year<2100) {var month = parseint (P.substr (4,2));
if (!isnan (month) && month>0 && month<13) {var day = parseint (P.substr (6,2)); if (!isnan (day) && day>0 && day<32) {showerror (' Do not use a date as a password!)
');
Return
}} var hasupper = false;
var haslow = false;
var hasnum = false;
var hasother = false;
for (var i=0; i<p.length; i++) {var c = p.charcodeat (i);
if (c>=65&&c<=90) hasupper=true; ELSE if (c>=97&&c<=122) haslow=true;
else if (c>=48&&c<=57) hasnum=true;
else hasother=true;
} var pwdnum = 0;
if (hasupper) pwdnum+=26;
if (Haslow) pwdnum+=26;
if (hasnum) pwdnum+=10;
if (hasother) pwdnum+=32;
var num = Math.pow (pwdnum, p.length);
var str = ' Password length: ' + p.length + ' strength: ' + Pwdnum + ' is expected to crack when: ' + formattime (num/(1024*1024*1024*2.4*2));
var span1 = document.getElementById (' span1 ');
Span1.style.color = ' Blue ';
span1.innerhtml = str;
}
4. Detect whether the keyboard caps lock (Caps lock key State)
Screenshot below:
The relevant code is as follows:
var $lock = false;
function Checkcapslock (FN)
{
document.documentElement.onkeypress = function (e)
{
var e = e | | | event;
var k = E.keycode | | E.which;
var s = E.shiftkey | | (k = = 16) | | false;
if (k>=65&&k<=90) $lock =!s;
if (k>=97&&k<=122) $lock =s;
FN ($lock);
Document.documentElement.onkeyup = function (e)
{
var e = e | | | event;
var k = E.keycode | | E.which;
if (k==20) $lock =! $lock;
FN ($lock);
}
}
Full instance code click here to download the site.
More readers interested in JavaScript-related content can view the site topics: "JavaScript switching effects and tips summary", "JavaScript Search Algorithm Skills Summary", "JavaScript animation effects and tips summary", " JavaScript error and debugging skills Summary, JavaScript data structure and algorithm skills summary, JavaScript traversal algorithm and skills summary and JavaScript mathematical calculation usage Summary
PS: Readers interested in the password can also refer to the site password-related tools:
Password Security online detection
High Strength Password Generator
MD5 Online Encryption Tool
Online generation of HTPASSWD tools
URL Web 16 Encryption tool
Escape Encryption/Decryption tool
Thunderbolt, Express, Cyclone URL encryption/decryption tool
I hope this article will help you with JavaScript programming.