顯示密碼安全性強度
<div?class="from-nav">
????????????????????????<div?class="Mtitle"><span>密碼:</span></div>
????????????????????????<div?class="Mright"><input?name="password"?type="password"?id="password"?size="20"?class="colorblue"?onfocus="this.className='colorfocus';"?onblur="this.className='colorblue';"?onkeyup="return?loadinputcontext(this);"?/><span>不得少于6個字符</span>
????????????????????????</div>
????</div>
????<div?class="from-nav">
????????????????????????<div?class="Mtitle"><span>密碼強度:</span></div>
????????????????????????<div?class="Mright">
<script?type="text/javascript">
????????var?PasswordStrength?={
????????????Level?:?["極佳","一般","較弱","太短"],
????????????LevelValue?:?[15,10,5,0],//強度值
????????????Factor?:?[1,2,5],//字符加數,分別為字母,數字,其它
????????????KindFactor?:?[0,0,10,20],//密碼含幾種組成的加數?
????????????Regex?:?[/[a-zA-Z]/g,/\d/g,/[^a-zA-Z0-9]/g]?//字符正則數字正則其它正則
????????????}
????????PasswordStrength.StrengthValue?=?function(pwd)
????????{
????????????var?strengthValue?=?0;
????????????var?ComposedKind?=?0;
????????????for(var?i?=?0?;?i?<?this.Regex.length;i++)
????????????{
????????????????var?chars?=?pwd.match(this.Regex[i]);
????????????????if(chars?!=?null)
????????????????{
????????????????????strengthValue?+=?chars.length?*?this.Factor[i];
????????????????????ComposedKind?++;
????????????????}
????????????}
????????????strengthValue?+=?this.KindFactor[ComposedKind];
????????????return?strengthValue;
????????}?
????????PasswordStrength.StrengthLevel?=?function(pwd)
????????{
????????????var?value?=?this.StrengthValue(pwd);
????????????for(var?i?=?0?;?i?<?this.LevelValue.length?;?i?++)
????????????{
????????????????if(value?>=?this.LevelValue[i]?)
????????????????????return?this.Level[i];
????????????}
????????}
????????function?loadinputcontext(o)
????????{
???????????var?showmsg=PasswordStrength.StrengthLevel(o.value);
???????????switch(showmsg)
???????????{
??????????????case?"太短":?showmsg+="?<img?src='images/level/1.gif'?width='88'?height='11'?/>";break;
??????????????case?"較弱":?showmsg+="?<img?src='images/level/2.gif'?width='88'?height='11'?/>";break;
??????????????case?"一般":?showmsg+="?<img?src='images/level/3.gif'?width='88'?height='11'?/>";break;
??????????????case?"極佳":?showmsg+="?<img?src='images/level/4.gif'?width='88'?height='11'?/>";break;
???????????}
???????????document.getElementById('showmsg').innerHTML?=?showmsg;
????????}
????????function?htmlEncode(source,?display,?tabs)
????????{
????????????function?special(source)
????????????{
????????????????var?result?=?'';
????????????????for?(var?i?=?0;?i?<?source.length;?i++)
????????????????{
????????????????????var?c?=?source.charAt(i);
????????????????????if?(c?<?'?'?||?c?>?'~')
????????????????????{
????????????????????????c?=?'&#'?+?c.charCodeAt()?+?';';
????????????????????}
????????????????????result?+=?c;
????????????????}
????????????????return?result;
????????????}
????????????function?format(source)
????????????{
????????????????//?Use?only?integer?part?of?tabs,?and?default?to?4
????????????????tabs?=?(tabs?>=?0)???Math.floor(tabs)?:?4;
????????????????//?split?along?line?breaks
????????????????var?lines?=?source.split(/\r\n|\r|\n/);
????????????????//?expand?tabs
????????????????for?(var?i?=?0;?i?<?lines.length;?i++)
????????????????{
????????????????????var?line?=?lines[i];
????????????????????var?newLine?=?'';
????????????????????for?(var?p?=?0;?p?<?line.length;?p++)
????????????????????{
????????????????????????var?c?=?line.charAt(p);
????????????????????????if?(c?===?'\t')
????????????????????????{
????????????????????????????var?spaces?=?tabs?-?(newLine.length?%?tabs);
????????????????????????????for?(var?s?=?0;?s?<?spaces;?s++)
????????????????????????????{
????????????????????????????????newLine?+=?'?';
????????????????????????????}
????????????????????????}
????????????????????????else
????????????????????????{
????????????????????????????newLine?+=?c;
????????????????????????}
????????????????????}
????????????????????//?If?a?line?starts?or?ends?with?a?space,?it?evaporates?in?html
????????????????????//?unless?it's?an?nbsp.
????????????????????newLine?=?newLine.replace(/(^?)|(?$)/g,?' ');
????????????????????lines[i]?=?newLine;
????????????????}
????????????????//?re-join?lines
????????????????var?result?=?lines.join('<br?/>');
????????????????//?break?up?contiguous?blocks?of?spaces?with?non-breaking?spaces
????????????????result?=?result.replace(/??/g,?'? ');
????????????????//?tada!
????????????????return?result;
????????????}
????????????var?result?=?source;
????????????//?ampersands?(&)
????????????result?=?result.replace(/\&/g,'&');
????????????//?less-thans?(<)
????????????result?=?result.replace(/\</g,'<');
????????????//?greater-thans?(>)
????????????result?=?result.replace(/\>/g,'>');
????????????if?(display)
????????????{
????????????????//?format?for?display
????????????????result?=?format(result);
????????????}
????????????else
????????????{
????????????????//?Replace?quotes?if?it?isn't?for?display,
????????????????//?since?it's?probably?going?in?an?html?attribute.
????????????????result?=?result.replace(new?RegExp('"','g'),?'"');
????????????}
????????????//?special?characters
????????????result?=?special(result);
????????????//?tada!
????????????return?result;
????????}
????????var?profile_username_toolong?=?'對不起,您的用戶名超過?20?個字符,請輸入一個較短的用戶名。';
????????var?profile_username_tooshort?=?'對不起,您輸入的用戶名小于3個字符,?請輸入一個較長的用戶名。';
????????var?profile_username_pass?=?"可用";
????????function?checkusername(username)
????????{
????????????var?unlen?=?username.replace(/[^\x00-\xff]/g,?"**").length;
????????????if(unlen?<?3?||?unlen?>?20)?{
????????????????document.getElementById("checkresult").innerHTML?=?"<font?color='#009900'>"?+?(unlen?<?3???profile_username_tooshort?:?profile_username_toolong)?+?"</font>";
????????????????return;
????????????}
????????????ajaxRead("tools/ajax.aspx?t=checkusername&username="?+?escape(username),?"showcheckresult(obj,'"?+?username?+?"');");
????????}
????????function?showcheckresult(obj,?username)
????????{
????????????var?res?=?obj.getElementsByTagName('result');
????????????var?resContainer?=?document.getElementById("checkresult");
????????????var?result?=?"";
????????????if?(res[0]?!=?null?&&?res[0]?!=?undefined)
????????????{
????????????????if?(res[0].childNodes.length?>?1)?{
????????????????????result?=?res[0].childNodes[1].nodeValue;
????????????????}?else?{
????????????????????result?=?res[0].firstChild.nodeValue;????????????
????????????????}
????????????}
????????????if?(result?==?"1")
????????????{
????????????????resContainer.innerHTML?=?"<font?color='#009900'>對不起,您輸入的用戶名?\""?+?htmlEncode(username,?true,?4)?+?"\"?已經被他人使用或被禁用,請選擇其他名字后再試。</font>";
????????????}
????????????else
????????????{
????????????????resContainer.innerHTML?=?profile_username_pass;
????????????}
????????}
</script>
<script?type="text/javascript"?src="templates/default/ajax.js"></script>
?????????????<span?id="showmsg"></span>
????????????????</div>
????</div>
????????????????????????<div?class="Mtitle"><span>密碼:</span></div>
????????????????????????<div?class="Mright"><input?name="password"?type="password"?id="password"?size="20"?class="colorblue"?onfocus="this.className='colorfocus';"?onblur="this.className='colorblue';"?onkeyup="return?loadinputcontext(this);"?/><span>不得少于6個字符</span>
????????????????????????</div>
????</div>
????<div?class="from-nav">
????????????????????????<div?class="Mtitle"><span>密碼強度:</span></div>
????????????????????????<div?class="Mright">
<script?type="text/javascript">
????????var?PasswordStrength?={
????????????Level?:?["極佳","一般","較弱","太短"],
????????????LevelValue?:?[15,10,5,0],//強度值
????????????Factor?:?[1,2,5],//字符加數,分別為字母,數字,其它
????????????KindFactor?:?[0,0,10,20],//密碼含幾種組成的加數?
????????????Regex?:?[/[a-zA-Z]/g,/\d/g,/[^a-zA-Z0-9]/g]?//字符正則數字正則其它正則
????????????}
????????PasswordStrength.StrengthValue?=?function(pwd)
????????{
????????????var?strengthValue?=?0;
????????????var?ComposedKind?=?0;
????????????for(var?i?=?0?;?i?<?this.Regex.length;i++)
????????????{
????????????????var?chars?=?pwd.match(this.Regex[i]);
????????????????if(chars?!=?null)
????????????????{
????????????????????strengthValue?+=?chars.length?*?this.Factor[i];
????????????????????ComposedKind?++;
????????????????}
????????????}
????????????strengthValue?+=?this.KindFactor[ComposedKind];
????????????return?strengthValue;
????????}?
????????PasswordStrength.StrengthLevel?=?function(pwd)
????????{
????????????var?value?=?this.StrengthValue(pwd);
????????????for(var?i?=?0?;?i?<?this.LevelValue.length?;?i?++)
????????????{
????????????????if(value?>=?this.LevelValue[i]?)
????????????????????return?this.Level[i];
????????????}
????????}
????????function?loadinputcontext(o)
????????{
???????????var?showmsg=PasswordStrength.StrengthLevel(o.value);
???????????switch(showmsg)
???????????{
??????????????case?"太短":?showmsg+="?<img?src='images/level/1.gif'?width='88'?height='11'?/>";break;
??????????????case?"較弱":?showmsg+="?<img?src='images/level/2.gif'?width='88'?height='11'?/>";break;
??????????????case?"一般":?showmsg+="?<img?src='images/level/3.gif'?width='88'?height='11'?/>";break;
??????????????case?"極佳":?showmsg+="?<img?src='images/level/4.gif'?width='88'?height='11'?/>";break;
???????????}
???????????document.getElementById('showmsg').innerHTML?=?showmsg;
????????}
????????function?htmlEncode(source,?display,?tabs)
????????{
????????????function?special(source)
????????????{
????????????????var?result?=?'';
????????????????for?(var?i?=?0;?i?<?source.length;?i++)
????????????????{
????????????????????var?c?=?source.charAt(i);
????????????????????if?(c?<?'?'?||?c?>?'~')
????????????????????{
????????????????????????c?=?'&#'?+?c.charCodeAt()?+?';';
????????????????????}
????????????????????result?+=?c;
????????????????}
????????????????return?result;
????????????}
????????????function?format(source)
????????????{
????????????????//?Use?only?integer?part?of?tabs,?and?default?to?4
????????????????tabs?=?(tabs?>=?0)???Math.floor(tabs)?:?4;
????????????????//?split?along?line?breaks
????????????????var?lines?=?source.split(/\r\n|\r|\n/);
????????????????//?expand?tabs
????????????????for?(var?i?=?0;?i?<?lines.length;?i++)
????????????????{
????????????????????var?line?=?lines[i];
????????????????????var?newLine?=?'';
????????????????????for?(var?p?=?0;?p?<?line.length;?p++)
????????????????????{
????????????????????????var?c?=?line.charAt(p);
????????????????????????if?(c?===?'\t')
????????????????????????{
????????????????????????????var?spaces?=?tabs?-?(newLine.length?%?tabs);
????????????????????????????for?(var?s?=?0;?s?<?spaces;?s++)
????????????????????????????{
????????????????????????????????newLine?+=?'?';
????????????????????????????}
????????????????????????}
????????????????????????else
????????????????????????{
????????????????????????????newLine?+=?c;
????????????????????????}
????????????????????}
????????????????????//?If?a?line?starts?or?ends?with?a?space,?it?evaporates?in?html
????????????????????//?unless?it's?an?nbsp.
????????????????????newLine?=?newLine.replace(/(^?)|(?$)/g,?' ');
????????????????????lines[i]?=?newLine;
????????????????}
????????????????//?re-join?lines
????????????????var?result?=?lines.join('<br?/>');
????????????????//?break?up?contiguous?blocks?of?spaces?with?non-breaking?spaces
????????????????result?=?result.replace(/??/g,?'? ');
????????????????//?tada!
????????????????return?result;
????????????}
????????????var?result?=?source;
????????????//?ampersands?(&)
????????????result?=?result.replace(/\&/g,'&');
????????????//?less-thans?(<)
????????????result?=?result.replace(/\</g,'<');
????????????//?greater-thans?(>)
????????????result?=?result.replace(/\>/g,'>');
????????????if?(display)
????????????{
????????????????//?format?for?display
????????????????result?=?format(result);
????????????}
????????????else
????????????{
????????????????//?Replace?quotes?if?it?isn't?for?display,
????????????????//?since?it's?probably?going?in?an?html?attribute.
????????????????result?=?result.replace(new?RegExp('"','g'),?'"');
????????????}
????????????//?special?characters
????????????result?=?special(result);
????????????//?tada!
????????????return?result;
????????}
????????var?profile_username_toolong?=?'對不起,您的用戶名超過?20?個字符,請輸入一個較短的用戶名。';
????????var?profile_username_tooshort?=?'對不起,您輸入的用戶名小于3個字符,?請輸入一個較長的用戶名。';
????????var?profile_username_pass?=?"可用";
????????function?checkusername(username)
????????{
????????????var?unlen?=?username.replace(/[^\x00-\xff]/g,?"**").length;
????????????if(unlen?<?3?||?unlen?>?20)?{
????????????????document.getElementById("checkresult").innerHTML?=?"<font?color='#009900'>"?+?(unlen?<?3???profile_username_tooshort?:?profile_username_toolong)?+?"</font>";
????????????????return;
????????????}
????????????ajaxRead("tools/ajax.aspx?t=checkusername&username="?+?escape(username),?"showcheckresult(obj,'"?+?username?+?"');");
????????}
????????function?showcheckresult(obj,?username)
????????{
????????????var?res?=?obj.getElementsByTagName('result');
????????????var?resContainer?=?document.getElementById("checkresult");
????????????var?result?=?"";
????????????if?(res[0]?!=?null?&&?res[0]?!=?undefined)
????????????{
????????????????if?(res[0].childNodes.length?>?1)?{
????????????????????result?=?res[0].childNodes[1].nodeValue;
????????????????}?else?{
????????????????????result?=?res[0].firstChild.nodeValue;????????????
????????????????}
????????????}
????????????if?(result?==?"1")
????????????{
????????????????resContainer.innerHTML?=?"<font?color='#009900'>對不起,您輸入的用戶名?\""?+?htmlEncode(username,?true,?4)?+?"\"?已經被他人使用或被禁用,請選擇其他名字后再試。</font>";
????????????}
????????????else
????????????{
????????????????resContainer.innerHTML?=?profile_username_pass;
????????????}
????????}
</script>
<script?type="text/javascript"?src="templates/default/ajax.js"></script>
?????????????<span?id="showmsg"></span>
????????????????</div>
????</div>
轉載于:https://www.cnblogs.com/Nina-piaoye/archive/2008/02/18/1071866.html
總結
- 上一篇: 读农民工兄弟学C#文章后的感觉
- 下一篇: 兔子多少钱一只啊?