Improved user experience form password strength hints

Source: Internet
Author: User

Function Description: When the user registers or changes the password, detects according to the user input and returns the result. Can effectively remind users to improve the security of the account.

  

Similar effect: Modify the password function in live.com

  

Run Code Box

   <ptml><pead><meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/><title> password </title><style type=" Text/css >body{; font-size:12px: Arial, Helvetica, Sans-serif; margin:0;} form{Margin:2em;} #chkResult {margin-left:53px;height:15px;} </style></pead><body><form name= "Form1" > <label for= "pwd" > User password </label> < Input type= "password" name= "pwd" onblur= "chkpwd (This)"/> <div id= "Chkresult" ></div> <label for= " PWD2 "> Repeat password </label> <input type=" password "name=" pwd2 "/></form><script type=" text/ JavaScript "> Function chkpwd (obj) {var t=obj.value; var id=getresult (t); Defines the corresponding message hint var msg=new Array (4); msg[0]= "Password is too short. "; msg[1]= "Bad password strength. "; msg[2]= "Password strength is good. "; msg[3]= "High password strength. "; var sty=new Array (4); sty[0]=-45; sty[1]=-30; sty[2]=-15; sty[3]=0; var col=new Array (4); Col[0]= "Gray"; col[1]= "Red"; Col[2]= "#ff6600"; Col[3]= "Green"; Set the display effect var bimg="/uploadpic/2007-7/200777164029934.gif";//a picture of the display using Var swidth=300; var sheight=15; var Bobj=document.getelementbyid ("Chkresult"); Bobj.style.fontsize= "12px"; Bobj.style.color=col[id]; Bobj.style.width=swidth + "px"; Bobj.style.height=sheight + "px"; Bobj.style.lineheight=sheight + "px"; bobj.style.background= "url (" + bimg + ") No-repeat Left" + sty[id] + "px"; Bobj.style.textindent= "20px"; Bobj.innerhtml= "detection hint:" + msg[id]; }//define detection function, return 0/1/2/3 respectively for invalid/bad/General/strong function GetResult (s) {if (S.length < 4) {returns 0; {var ls = 0; if (S.match (/[a-z]/ig)) {ls++; } if (S.match (/[0-9]/ig)) {ls++; } if (S.match (/. [ ^a-z0-9]) (/ig)) {ls++; } if (S.length < 6 && ls > 0) {ls--; return ls}</script></body></ptml><script language= ' Javascript ' > var now = new Date (); document.write (" <noscript> </ Noscript>
Run codeCopy CodeSave Code

  How to use:

First step: Save the picture

The second step: according to your needs to modify the JS file in the image address. As shown below:

var bimg= "pwdlen.gif";//a picture of the display

Step three: Refer to the script file in the page you want to detect, as follows:

<script type= "Text/javascript" src= "Chkpwd.js" ></script>

Fourth step: In the form of the Web page, locate the Password entry box to add the onblur event driver, and then add a div as follows:

<input type= "password" name= "pwd" onblur= "chkpwd" (This)/>
<div id= "Chkresult" > Strength testing </div>

The fifth step: according to your page needs to redefine the placement of #chkresult through style sheet CSS to fit the overall layout of your Web page.



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.