生成强密码
主要代码:
function getPwd(n)
{
var s = '';
while(n--)
s += String.fromCharCode(33 + Math.floor(Math.random()*(126-33)))
document.getElementById('txt1').value = s;
}
计算密码破解时间
密码强度:
密码位数:
(假设使用每秒2.4G的双核CPU计算,不考虑其他因素,穷举破解)
主要代码:
function getTime()
{
var str = '预计破解用时:';
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 '小于1秒!';
s = Math.floor(s);
if(s >= 1) str = s % 60 + '秒' + str;
s = Math.floor(s / 60);
if(s >= 1) str = s % 60 + '分' + str;
s = Math.floor(s / 60);
if(s >= 1) str = s % 24 + '时' + str;
s = Math.floor(s / 24);
if(s >= 1) str = s + '天' + str;
return str;
}
密码安全检测
检测键盘是否大写锁定(Caps Lock键状态)
请按字母键测试:
主要代码:
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);
}
}
checkCapsLock(function(bo){
document.getElementById('spanCapsLock').innerHTML = bo?'大写':'小写';
});
欢迎转载,转载请注明:转载自[ http://www.cnblogs.com/zjfree/ ]