JS's judgment on the strength of the password

Source: Internet
Author: User

<div class= "Email_reg M_part" >
<form class= "Reg_form" id= "Reg_form" >
<p> Email Registration </p>
<div class= "Control" >
<label> email </label><input class= "email" name= "Email" >
<span> please fill in my usual email address, which will be used as login account </span>
</div>
<div class= "Control" >
<label> password </label><input type= "password" name= "password" >
<span> letters, numbers or English symbols, 6-20-bit </span>
</div>
<div class= "Control" >
<label> Confirm password </label><input type= "password" name= "Confirmpwd" >
<span> Please enter your password again </span>
</div>
<input class= "Submit" id= "submit_btn" onclick= "return false" type= "submit" value= "register" >
</form>
</div>

<script>

$ ("#reg_form"). Validate ({
Ok:function () {
Alert ("Login! ");
}
});

</script>


(function (jQuery) {
"Use strict";
(function (factor) {
if (jQuery &&!jquery.fn.validate) {
Factor ($);
}
}) (function ($) {
var Flagall = {
Email:false,
Password:false,
Samepwd:false
};
var methods = {
Settings:null,
Init:function (item) {
Methods.settings = $.extend (True,{},$.fn.validate.defaults,item);
Return This.each (function () {
var cur = $ (this);
var Checkitem = Cur.find ("input[name]");
Methods.subcheck (cur);
Methods.checkitem (Checkitem);
});
},
Subcheck:function (Box) {
var btn = box.find ("input[type= ' Submit ']");
Btn.on ("click", Function () {
Methods.allcheck (box);
});
},
Allcheck:function (Box) {
var Checkitem = Box.find ("input[name]");
$.each (Checkitem,function (i,v) {
var cur = $ (v);
Methods.bluee (cur);
METHODS.CHECKFMT (cur);
});
if (flagall.email && flagall.password && flagall.samepwd) {
Alert ("Submit");
}
},
Checkitem:function (item) {
$.each (Item,function () {
var cur = $ (this);
Methods.checksingle (cur);
});
},
Checksingle:function (item) {
Item.on ("Blur", function () {
Methods.bluee (item);
METHODS.CHECKFMT (item);
});
Item.keydown (function (e) {
var code = E.keycode;
if (code = = 13) {
Methods.allcheck (item);
}
}). KeyUp (function (e) {
Methods.bluee (item);
});
},
Bluee:function (item) {
var val = item.val ();
if (val = = "") {
var txt = methods.gettype (item);
Methods.errorinfo (Item,txt);
}else{
var error = Item.next (". Error");
Error.length > 0? Error.remove (): ";
METHODS.CHECKFMT (item); Edge Input Change Verification
}
},
Gettype:function (item) {
var type = item.attr ("name");
var txt = "";
Switch (type) {
Case "Email":
txt = METHODS.SETTINGS.EMAILTXT;
Break
Case "Password":
txt = METHODS.SETTINGS.PWDTXT;
Break
Case "Confirmpwd":
txt = METHODS.SETTINGS.CONFIRMTXT;
Break
}
return txt;
},
Checkfmt:function (item) {
var val = item.val ();
var type = item.attr ("name");
Switch (type) {
Case "Email":
METHODS.CHECKEMAILFMT (Item,val);
Break
Case "Password":
METHODS.CHECKPWDFMT (Item,val);
Break
Case "Confirmpwd":
METHODS.CHECKPWDFMT (item,val,true);
}
},
Checkemailfmt:function (item,val) {
var reg,info;
Reg =/^ ([a-za-z0-9_-]) [email protected] ([a-za-z0-9_-]) + (\.com) $/;
info = "Email address is not correct, please re-enter";
var flag = Reg.test (val);
if (flag) {
Flagall.email= true;
}else{
Methods.errorinfo (Item,info);
Flagall.email = false;
}
},

Checkpwdfmt:function (item,val,state) {
var reg,info;
Reg =/^[-,.?:; ' " ~ ~ ' #%<>=_\@\*\$\^\&\ (\) \{\}\[\]\/| 0-9 | A-Z |a-z]{6,20}$/;
info = "Please enter 6-20 digits of reasonable character";
var flag = Reg.test (val);
if (flag) {
if (state) {
Methods.checkdoublepwd (Val,item);
}else{
Methods.checksafe (Val,item);
flagall.password= true;
}
}else{
Methods.errorinfo (Item,info);
State? Flagall.samepwd = False:flagAll.password = false;
}
},
Checkdoublepwd:function (Val,item) {
var pwd = $ ("input[name= ' password ')"). Val ();
if (pwd! = val) {
Flagall.samepwd = false;
var txt = "Two times password inconsistent, please re-enter";
Methods.errorinfo (Item,txt);
}else{
Flagall.samepwd = true;
}
},
Checksafe:function (Val,item) {
var Modes;
for (Var i=0;i<val.length;i++) {
Password mode
Modes|=methods. Charmode (Val.charcodeat (i));
}
var level = Methods.bittotal (Modes);
Methods.showlevel (Level,item);
},
Showlevel:function (Level,item) {
Switch (level) {
Case 1:
var txt = "Password set too simple, security weak";
Methods.errorinfo (item,txt, "error");
Break
Case 2:
var txt = "Password security";
Methods.errorinfo (Item,txt, "middlepwd");
Break
Default:
var txt = "Password security strong";
Methods.errorinfo (Item,txt, "strongpwd");
}
},
Charmode:function (in) {
if (in>=48 && in <=57)//Digital
return 1;
if (in>=65 && in <=90)//Uppercase
return 2;
if (in>=97 && in <=122)//lowercase
return 4;
Else
return 8;
},
Bittotal:function (num) {
var modes=0;
for (Var i=0;i<6;i++) {
if (num & 1) modes++;
num>>>=1;
}
return modes;
},
/*checksafe:function (Val,item) {
var reg1 =/^\d+$/,
REG2 =/^[a-za-z]$/,
Reg3 =/^ (\d*) ([a-za-z]{1,2}) (\d*) $/,
REG4 =/^ ([a-za-z]*) (\d{1,2}) ([a-za-z]*] $/;
var regm =/^ ([a-za-z0-9]*) ([-,.?:; ' " ~ ' #%<>=_\@\*\$\^\&\ (\) \{\}\[\]\/]{1,2}) ([a-za-z0-9]*) $/;
if (Reg1.test (val) | | | reg2.test (val) | | reg3.test (val) | | reg4.test (val)) && val.length = = 6) {
var txt = "Password set too simple, security weak";
Methods.errorinfo (item,txt, "error");
}else if (Regm.test (val)) {
var txt = "Password security";
Methods.errorinfo (Item,txt, "middlepwd");
}else{
var txt = "Password security strong";
Methods.errorinfo (Item,txt, "strongpwd");
}
},*/
Errorinfo:function (ITEM,TXT,CLS) {
var scls = CLS | | "Error";
var div = "<span class= ' Validate_cls" +scls+ ">" +txt+ "</span>";
if (Item.next (". Validate_cls"). Length = = 0) {
$ (div). InsertAfter (item);
}else{
var box = Item.next (". Validate_cls");
box.html (TXT). Removeclass (). addclass ("Validate_cls"). addclass (SCLS);
}
}
};
$.fn.validate = function (param) {
Return methods.init.apply (This,param);
};
$.fn.validate.defaults = {
Emailtxt: "Please enter your mailbox",
Pwdtxt: "Please enter your password",
Confirmtxt: "Please Confirm password"
};
});
}) (JQuery);

JS's judgment on the strength of the password

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.