码迷,mamicode.com
首页 > 其他好文 > 详细

密码强度判断

时间:2015-11-20 17:17:41      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

密码强度判断

如图

======================

技术分享

 

==================HTML========================

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en">
<html>

<head>
<title> Reset password</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="author" content="">
<meta name="keywords" content="">
<meta name="description" content="">
<link href="css/reset-password.css" type="text/css" rel="stylesheet" />
<script language="javascript" type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
</head>

<body>
<!--head-->
<div class="head">
<div class="header">
<h1 class="logo">
<a href="javascript:void(0);" class="logo-img"></a>
</h1>
<h2 class="logo-title">重置密码</h2>
<ul class="nav">
<li><a href="javascript:void(0);">注册</a></li>
<li><a href="javascript:void(0);">登录</a></li>
<li><a href="javascript:void(0);">安全退出</a></li>
</ul>
</div>

</div>
<!--head-->
<!--container-->
<div class="container">
<div class="content">
<p class="content-tip">
请输入您需要重置的密码
</p>
<div class="checksum-form">
<label class="checksum-label">输入新密码</label>
<input type="password" placeholder="请输入新密码" class="checksum-input" name="tbPassword" id="tbPassword" />
<div class="checksum-wrap">
<div class="strength-back" id=‘strengthLevel-1‘> </div>
<div class="strength-back" id=‘strengthLevel-2‘> </div>
<div class="strength-back" id=‘strengthLevel-3‘> </div>
<div class="strength-back-current"> 弱</div>
<div class="strength-back-current"> 中</div>
<div class="strength-back-current"> 强</div>
</div>
<label class="checksum-label">确认新密码</label>
<input type="password" placeholder="请再次输入新密码" class="checksum-input" name="RetbPassword" id="RetbPassword" />
<div id="system_msg" class="warn">密码输入不正确!</div>
<button type="submit" class="checksum-btn">确定</button>
</div>
</div>
<p class="copyright">
版权所有
</p>
</div>
<!--container-->

<script type="text/javascript">
$(‘#tbPassword‘).on("focus", function() {
$(‘#strengthLevel-1‘).addClass(‘strength-blur‘);
$(‘#tbPassword‘).keyup();
});
$(‘#tbPassword‘).keyup(function() {
var __th = $(this);
if (!__th.val()) {
Primary();
return;
}
if (__th.val().length < 6) {
Weak();
return;
}
var _r = checkPassword(__th);
if (_r < 1) {
Primary();
return;
}
if (_r > 0 && _r < 2) {
Weak();
} else if (_r >= 2 && _r < 4) {
Medium();
} else if (_r >= 4) {
Tough();
}
});

function Primary() {
$(‘#strengthLevel-1‘).attr(‘class‘, ‘strength-back‘);
$(‘#strengthLevel-2‘).attr(‘class‘, ‘strength-back‘);
$(‘#strengthLevel-3‘).attr(‘class‘, ‘strength-back‘);
}

function Weak() {
$(‘#strengthLevel-1‘).attr(‘class‘, ‘strength-blur‘);
$(‘#strengthLevel-2‘).attr(‘class‘, ‘strength-back‘);
$(‘#strengthLevel-3‘).attr(‘class‘, ‘strength-back‘);
}

function Medium() {
$(‘#strengthLevel-1‘).attr(‘class‘, ‘strength-blur‘);
$(‘#strengthLevel-2‘).attr(‘class‘, ‘strength-blur2‘);
$(‘#strengthLevel-3‘).attr(‘class‘, ‘strength-back‘);
}

function Tough() {
$(‘#strengthLevel-1‘).attr(‘class‘, ‘strength-blur‘);
$(‘#strengthLevel-2‘).attr(‘class‘, ‘strength-blur2‘);
$(‘#strengthLevel-3‘).attr(‘class‘, ‘strength-blur3‘);
}

function checkPassword(pwdinput) {
var maths, smalls, bigs, corps, cat, num;
var str = $(pwdinput).val()
var len = str.length;
var cat = /.{16}/g
if (len == 0) {
return 1;
}
if (len > 16) {
$(pwdinput).val(str.match(cat)[0]);
}
cat = /.*[\u4e00-\u9fa5]+.*$/
if (cat.test(str)) {
return -1;
}
cat = /\d/;
var maths = cat.test(str);
cat = /[a-z]/;
var smalls = cat.test(str);
cat = /[A-Z]/;
var bigs = cat.test(str);
var corps = corpses(pwdinput);
var num = maths + smalls + bigs + corps;
if (len < 6) {
return 1;
}
if (len >= 6 && len <= 8) {
if (num == 1) return 1;
if (num == 2 || num == 3) return 2;
if (num == 4) return 3;
}
if (len > 8 && len <= 11) {
if (num == 1) return 2;
if (num == 2) return 3;
if (num == 3) return 4;
if (num == 4) return 5;
}
if (len > 11) {
if (num == 1) return 3;
if (num == 2) return 4;
if (num > 2) return 5;
}
}

function corpses(pwdinput) {
var cat = /./g;
var str = $(pwdinput).val();
var sz = str.match(cat)
for (var i = 0; i < sz.length; i++) {
cat = /\d/;
maths_01 = cat.test(sz[i]);
cat = /[a-z]/;
smalls_01 = cat.test(sz[i]);
cat = /[A-Z]/;
bigs_01 = cat.test(sz[i]);
if (!maths_01 && !smalls_01 && !bigs_01) {
return true;
}
}
return false;
}



</script>

</body>

</html>

======CSS=============

@charset "utf-8";
/*css reset*/
ul {
list-style: none;
}
a {
text-decoration: none;
}

body,
h1,
h2,
h3,
h4,
h5,
h6,
p,
ul,
ol,
form {
margin: 0;
padding: 0;
}
html,
body {
width: 100%;
height: 100%;
background: #fff;
font-size: 12px;
font-family: Microsoft YaHei ;
SimSun, Arial, Helvetica, sans-serif;
}
/*css reset*/

/*head*/

.head {
width: 100%;
height: 74px;
background-color: #fff;
border-bottom: 1px solid #e3e3e3;
}

.header {
width: 1000px;
height: 74px;
margin: 0 auto;
}

.header .logo {
float: left;
}

.logo .logo-img {
width: 275px;
height: 74px;
display: inline-block;
background: url(../images/guandu.png) no-repeat 0 10px;
}

.header .logo-title {
float: left;
display: inline-block;
width: auto;
height: 30px;
padding: 13px 0 0 15px;
line-height: 30px;
font-size: 24px;
color: gray;
border-left: 2px solid gray;
margin-top: 10px;
}

h2 {
font-weight: 500;
}

.header .nav {
width: auto;
height: 14px;
float: right;
line-height: 14px;
margin-top: 30px;
}

.header .nav li {
float: left;
padding: 0 15px 0 0;
margin-right: 15px;
border-right: 1px solid #4d4d4d;
}

.nav li a {
color: #4d4d4d;
font-size: 14px;
}


/*head*/


/*container*/

.container {
width: 100%;
height: 100%;
background-color: #f9f9f9;
border-top: 1px solid #fff;
}

.container .content {
width: 732px;
height: auto;
padding: 20px;
margin-bottom: 30px;
background-color: #fff;
border: 1px solid #e3e3e3;
border-radius: 2px;
box-shadow: 1px 1px 2px #f0f0f0;
margin: 20px auto;
}

.content .content-tip {
padding-bottom: 10px;
border-bottom: 1px solid #eee;
color: #4D4D4D;
vertical-align: middle;
line-height: 25px;
height: 20px;
font-size: 14px;
text-indent: 2em;
background: url(../images/icon-font.png) no-repeat;
}

.checksum-form {
margin: 20px auto 3px;
width: 80%;
text-align: center;
}

.checksum-form .checksum-label {
font-size: 16px;
margin-right: 10px;
color: #4d4d4d;
text-align: right;
width: 90px;
display: inline-block;
}

.checksum-form .checksum-input {
width: 190px;
padding: 8px 9px;
line-height: 18px;
border: 1px solid #e0e0e0;
}

.content .checksum-btn {
display: block;
width: 160px;
height: 50px;
line-height: 50px;
border: none;
overflow: hidden;
text-align: center;
background: #69b3f2;
font-size: 26px;
border-radius: 2px;
color: #FFF;
margin: 35px auto 50px 238px;
cursor: pointer;
}

.checksum-btn:hover {
background: #7cbdf5;
color: #FFFFFF;
}

.container .copyright {
color: #858585;
text-align: center;
margin-top: 100px;
}

.checksum-wrap {
width: 202px;
height: 25px;
margin: 5px auto 5px 238px;
}

.strength-back-current {
float: left;
width: 62px;
margin-left: 5px;
text-align: center;
color: #b0adad;
font-size: 12px;
}

.strength-back {
float: left;
background: #d6d3d3;
width: 62px;
height: 4px;
margin-top: 5px;
_margin-top: 0px;
margin-left: 5px;
_height: 2px;
font-size: 0px;
}

.strength-blur {
float: left;
background: #ff3300;
width: 62px;
height: 4px;
margin-top: 5px;
margin-left: 5px;
_margin-top: 0px;
_height: 2px;
font-size: 0px;
}

.strength-blur2 {
float: left;
background: #099;
width: 62px;
height: 4px;
margin-top: 5px;
margin-left: 5px;
_margin-top: 0px;
_height: 2px;
font-size: 0px;
}

.strength-blur3 {
float: left;
background: #060;
width: 62px;
height: 4px;
margin-top: 5px;
margin-left: 5px;
_margin-top: 0px;
_height: 2px;
font-size: 0px;
}
.checksum-form .warn{
margin-top: 10px;
color: red;
}
.content .tick{
width: 250px;
height: 40px;
line-height: 40px;
margin: 80px auto;
background: url(../images/tick.png) no-repeat 0 0;
text-indent: 2.5em;
}
/*container/

 

==========================

下载地址:

http://files.cnblogs.com/files/leshao/%E5%AF%86%E7%A0%81%E5%BC%BA%E5%BA%A6%E5%88%A4%E6%96%AD.rar

 

密码强度判断

标签:

原文地址:http://www.cnblogs.com/leshao/p/4981047.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!