• Страница 1 из 1
  • 1
Проверка пароля при регистр.
otpmДата: Суббота, 31.Янв.2009, 16:27 | Сообщение # 1
Admin
Сообщений: 554
« 3 »
Статус: :-(
Скрипт для того чтоб при регистрации проверялся пароль!

Code
<script type="text/javascript">   
var m_strUpperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";   
var m_strLowerCase = "abcdefghijklmnopqrstuvwxyz";   
var m_strNumber = "0123456789";   
var m_strCharacters = "_-"   

// Check password   
function checkPassword(strPassword)   
{   
   // Reset combination count   
   var nScore = 0;   
     
   // Password length   
   // -- Less than 4 characters   
   if (strPassword.length < 5)   
   {   
   nScore += 5;   
   }   
   // -- 5 to 7 characters   
   else if (strPassword.length > 4 && strPassword.length < 8)   
   {   
   nScore += 10;   
   }   
   // -- 8 or more   
   else if (strPassword.length > 7)   
   {   
   nScore += 25;   
   }   

   // Letters   
   var nUpperCount = countContain(strPassword, m_strUpperCase);   
   var nLowerCount = countContain(strPassword, m_strLowerCase);   
   var nLowerUpperCount = nUpperCount + nLowerCount;   
   // -- Letters are all lower case   
   if (nUpperCount == 0 && nLowerCount != 0)   
   {   
   nScore += 10;   
   }   
   // -- Letters are upper case and lower case   
   else if (nUpperCount != 0 && nLowerCount != 0)   
   {   
   nScore += 20;   
   }   
     
   // Numbers   
   var nNumberCount = countContain(strPassword, m_strNumber);   
   // -- 1 number   
   if (nNumberCount == 1)   
   {   
   nScore += 10;   
   }   
   // -- 3 or more numbers   
   if (nNumberCount >= 3)   
   {   
   nScore += 20;   
   }   
     
   // Characters   
   var nCharacterCount = countContain(strPassword, m_strCharacters);   
   // -- 1 character   
   if (nCharacterCount == 1)   
   {   
   nScore += 10;   
   }   
   // -- More than 1 character   
   if (nCharacterCount > 1)   
   {   
   nScore += 25;   
   }   
     
   // Bonus   
   // -- Letters and numbers   
   if (nNumberCount != 0 && nLowerUpperCount != 0)   
   {   
   nScore += 2;   
   }   
   // -- Letters, numbers, and characters   
   if (nNumberCount != 0 && nLowerUpperCount != 0 && nCharacterCount != 0)   
   {   
   nScore += 3;   
   }   
   // -- Mixed case letters, numbers, and characters   
   if (nNumberCount != 0 && nUpperCount != 0 && nLowerCount != 0 && nCharacterCount != 0)   
   {   
   nScore += 5;   
   }   
     
     
   return nScore;   
}   
     
// Runs password through check and then updates GUI   
function runPassword(strPassword, strFieldID)   
{   
   // Check password   
   var nScore = checkPassword(strPassword);   
     
   // Get controls   
   var ctlBar = document.getElementById(strFieldID + "_bar");   
   var ctlText = document.getElementById(strFieldID + "_text");   
   if (!ctlBar || !ctlText)   
   return;   
     
   // Set new width   
   ctlBar.style.width = nScore + "%";   

   // Color and text   
   // -- ,езупречный   
   if (nScore >= 90)   
   {   
   var strText = "jтличный пароль! uлавное не забыть его :-)";   
   var strColor = "#0ca908";   
   }   
   // -- хороший   
   else if (nScore >= 80)   
   {   
   var strText = "хороший";   
   var strColor = "#00CCFF";   
   }   
   // -- довольно нормальный   
   else if (nScore >= 70)   
   {   
   var strText = "достаточно неплохо";   
   var strColor = "#5a74e3";   
   }   
   // -- нормальный   
   else if (nScore >= 50)   
   {   
   var strText = "нормально";   
   var strColor = "#FF6600";   
   }   
   // -- слабый   
   else if (nScore >= 25)   
   {   
   var strText = "слабенько";   
   var strColor = "#e7d61a";   
   }   
   // -- очень плохой   
   else   
   {   
   var strText = "ужас, qwerty и то лучше!!! :-)";   
   var strColor = "#e71a1a";   
   }   
   ctlBar.style.backgroundColor = strColor;   
   ctlText.innerHTML = "<span style='color: " + strColor + ";'>" + strText + " - " + nScore + "%</span>";   
}   
     
// Checks a string for a list of characters   
function countContain(strPassword, strCheck)   
{   
   // Declare variables   
   var nCount = 0;   
     
   for (i = 0; i < strPassword.length; i++)   
   {   
   if (strCheck.indexOf(strPassword.charAt(i)) > -1)   
   {   
   nCount++;   
   }   
   }   
     
   return nCount;   
}   
</script>   

<table border="0" cellspacing="1" cellpadding="2" width="100%" class="manTable" id="siM63">   
<?if($ERROR$)?>   
<tr id="siM1"><td colspan="2" align="center" class="manTdError" id="siM2">$ERROR$</td></tr><tr><td height="10" class="manTdSep" colspan="2"><hr class="manHr" /></td></tr>   
<?endif?>   
<?if($LOGIN_FL$)?>   
<tr id="siM42"><td class="manTd1" width="35%" id="siM43">$LOGIN_SIGN$</td><td class="manTd2" id="siM44">$LOGIN_FL$</td></tr><tr><td height="10" class="manTdSep" colspan="2"><hr class="manHr" /></td></tr>   
<?endif?>   
<?if($PASSWORD_FL$)?>   
<tr id="siM45"><td class="manTd1" id="siM46">$PASSWORD_SIGN$</td><td class="manTd2" id="siM47"><input id="siF14" class="manFlPassw" name="password" size="20" style="width: 100%;" maxlength="15" type="password" onkeyup="runPassword(this.value, 'mypassword');"></td></tr>   
<?endif?>   
<?if($PASSWORD1_FL$)?>   
<tr id="siM48"><td class="manTd1" id="siM49">$PASSWORD1_SIGN$</td><td class="manTd2" id="siM50">$PASSWORD1_FL$</td></tr>   

<tr>   
<td width="130" height="25">«защита пароля:</td>   
<td><b><div align="center" id="mypassword_text">для начала введите пароль!</div></b>   
<div style="width: 99%;">   
<div id="mypassword_bar" style="font-size: 1px; height: 2px; width: 0px; border: 1px solid white;"></div></div></td>   
</tr>   

<tr><td height="10" class="manTdSep" colspan="2"><hr class="manHr" /></td></tr>   
<?else?><tr><td height="10" class="manTdSep" colspan="2"><hr class="manHr" /></td></tr>   
<?endif?>   
<?if($GROUP_FL$)?>   
<tr id="siM70"><td class="manTd1" id="siM71">$GROUP_SIGN$</td><td class="manTd2" id="siM72">$GROUP_FL$</td></tr><tr><td height="10" class="manTdSep" colspan="2"><hr class="manHr" /></td></tr>   
<?endif?>   
<?if($NAME_FL$)?>   
<tr id="siM51"><td class="manTd1" id="siM52">$NAME_SIGN$</td><td class="manTd2" id="siM53">$NAME_FL$</td></tr><tr><td height="10" class="manTdSep" colspan="2"><hr class="manHr" /></td></tr>   
<?endif?>   
<?if($EMAIL_FL$)?>   
<tr id="siM54"><td class="manTd1" id="siM55">$EMAIL_SIGN$</td><td class="manTd2" id="siM56">$EMAIL_FL$</td></tr><tr><td height="10" class="manTdSep" colspan="2"><hr class="manHr" /></td></tr>   
<?endif?>   
<?if($WWW_FL$)?>   
<tr id="siM3"><td class="manTd1" id="siM4">$WWW_SIGN$</td><td class="manTd2" id="siM5">$WWW_FL$</td></tr><tr><td height="10" class="manTdSep" colspan="2"><hr class="manHr" /></td></tr>   
<?endif?>   
<?if($ICQ_FL$)?>   
<tr id="siM6"><td class="manTd1" id="siM7">$ICQ_SIGN$</td><td class="manTd2" id="siM8">$ICQ_FL$</td></tr><tr><td height="10" class="manTdSep" colspan="2"><hr class="manHr" /></td></tr>   
<?endif?>   
<?if($AOL_FL$)?>   
<tr id="siM9"><td class="manTd1" id="siM10">$AOL_SIGN$</td><td class="manTd2" id="siM11">$AOL_FL$</td></tr><tr><td height="10" class="manTdSep" colspan="2"><hr class="manHr" /></td></tr>   
<?endif?>   
<?if($MSN_FL$)?>   
<tr id="siM12"><td class="manTd1" id="siM13">$MSN_SIGN$</td><td class="manTd2" id="siM14">$MSN_FL$</td></tr><tr><td height="10" class="manTdSep" colspan="2"><hr class="manHr" /></td></tr>   
<?endif?>   
<?if($YAHOO_FL$)?>   
<tr id="siM15"><td class="manTd1" id="siM16">$YAHOO_SIGN$</td><td class="manTd2" id="siM17">$YAHOO_FL$</td></tr><tr><td height="10" class="manTdSep" colspan="2"><hr class="manHr" /></td></tr>   
<?endif?>   
<?if($BIRTHDAY_FL$)?>   
<tr id="siM30"><td class="manTd1" id="siM31">$BIRTHDAY_SIGN$</td><td class="manTd2" id="siM32">$BIRTHDAY_FL$</td></tr><tr><td height="10" class="manTdSep" colspan="2"><hr class="manHr" /></td></tr>   
<?endif?>   
<?if($GENDER_FL$)?>   
<tr id="siM27"><td class="manTd1" id="siM28">$GENDER_SIGN$</td><td class="manTd2" id="siM29">$GENDER_FL$</td></tr><tr><td height="10" class="manTdSep" colspan="2"><hr class="manHr" /></td></tr>   
<?endif?>   
<?if($COUNTRY_FL$)?>   
<tr id="siM18"><td class="manTd1" id="siM19">$COUNTRY_SIGN$</td><td class="manTd2" id="siM20">$COUNTRY_FL$</td></tr><tr><td height="10" class="manTdSep" colspan="2"><hr class="manHr" /></td></tr>   
<?endif?>   
<?if($STATE_FL$)?>   
<tr id="siM21"><td class="manTd1" id="siM22">$STATE_SIGN$</td><td class="manTd2" id="siM23">$STATE_FL$</td></tr><tr><td height="10" class="manTdSep" colspan="2"><hr class="manHr" /></td></tr>   
<?endif?>   
<?if($CITY_FL$)?>   
<tr id="siM24"><td class="manTd1" id="siM25">$CITY_SIGN$</td><td class="manTd2" id="siM26">$CITY_FL$</td></tr><tr><td height="10" class="manTdSep" colspan="2"><hr class="manHr" /></td></tr>   
<?endif?>   
<?if($AVATAR_FL$)?>   
<tr id="siM36"><td class="manTd1" valign="top" id="siM37">$AVATAR_SIGN$</td><td class="manTd2" id="siM38">$AVATAR_FL$</td></tr><tr><td height="10" class="manTdSep" colspan="2"><hr class="manHr" /></td></tr>   
<?endif?>   
<?if($SIGNATURE_FL$)?>   
<tr id="siM33"><td class="manTd1" id="siM34">$SIGNATURE_SIGN$</td><td class="manTd2" id="siM35">$SIGNATURE_FL$</td></tr><tr><td height="10" class="manTdSep" colspan="2"><hr class="manHr" /></td></tr>   
<?endif?>   
<?if($SUBSCRIPTION_FL$)?>   
<tr id="siM39"><td class="manTd1" id="siM40">$SUBSCRIPTION_SIGN$</td><td class="manTd2" id="siM41">$SUBSCRIPTION_FL$</td></tr><tr><td height="10" class="manTdSep" colspan="2"><hr class="manHr" /></td></tr>   
<?endif?>   
<?if($OPTIONS_FL$)?>   
<tr id="siM63"><td class="manTd1" id="siM64">$OPTIONS_SIGN$</td><td class="manTd2" id="siM65">$OPTIONS_FL$</td></tr><tr><td height="10" class="manTdSep" colspan="2"><hr class="manHr" /></td></tr>   
<?endif?>   
<?if($SECURITY_CODE_FL$)?>   
<tr id="siM60"><td class="manTd1" id="siM61">$SECURITY_CODE_SIGN$</td><td class="manTd2" id="siM62">$SECURITY_CODE_FL$</td></tr><tr><td height="10" class="manTdSep" colspan="2"><hr class="manHr" /></td></tr>   
<?endif?>   
<tr id="siM64"><td class="manTdBut" colspan="2" align="center" id="siM65"><input class="manFlSbm" id="siF20" type="submit" name="sbm" value="$SUBMIT_SIGN$" /></td></tr>   
</table>   

<script type="text/javascript">   
var m_strUpperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";   
var m_strLowerCase = "abcdefghijklmnopqrstuvwxyz";   
var m_strNumber = "0123456789";   
var m_strCharacters = "_-"   

// Check password   
function checkPassword(strPassword)   
{   
   // Reset combination count   
   var nScore = 0;   
     
   // Password length   
   // -- Less than 4 characters   
   if (strPassword.length < 5)   
   {   
   nScore += 5;   
   }   
   // -- 5 to 7 characters   
   else if (strPassword.length > 4 && strPassword.length < 8)   
   {   
   nScore += 10;   
   }   
   // -- 8 or more   
   else if (strPassword.length > 7)   
   {   
   nScore += 25;   
   }   

   // Letters   
   var nUpperCount = countContain(strPassword, m_strUpperCase);   
   var nLowerCount = countContain(strPassword, m_strLowerCase);   
   var nLowerUpperCount = nUpperCount + nLowerCount;   
   // -- Letters are all lower case   
   if (nUpperCount == 0 && nLowerCount != 0)   
   {   
   nScore += 10;   
   }   
   // -- Letters are upper case and lower case   
   else if (nUpperCount != 0 && nLowerCount != 0)   
   {   
   nScore += 20;   
   }   
     
   // Numbers   
   var nNumberCount = countContain(strPassword, m_strNumber);   
   // -- 1 number   
   if (nNumberCount == 1)   
   {   
   nScore += 10;   
   }   
   // -- 3 or more numbers   
   if (nNumberCount >= 3)   
   {   
   nScore += 20;   
   }   
     
   // Characters   
   var nCharacterCount = countContain(strPassword, m_strCharacters);   
   // -- 1 character   
   if (nCharacterCount == 1)   
   {   
   nScore += 10;   
   }   
   // -- More than 1 character   
   if (nCharacterCount > 1)   
   {   
   nScore += 25;   
   }   
     
   // Bonus   
   // -- Letters and numbers   
   if (nNumberCount != 0 && nLowerUpperCount != 0)   
   {   
   nScore += 2;   
   }   
   // -- Letters, numbers, and characters   
   if (nNumberCount != 0 && nLowerUpperCount != 0 && nCharacterCount != 0)   
   {   
   nScore += 3;   
   }   
   // -- Mixed case letters, numbers, and characters   
   if (nNumberCount != 0 && nUpperCount != 0 && nLowerCount != 0 && nCharacterCount != 0)   
   {   
   nScore += 5;   
   }   
     
     
   return nScore;   
}   
     
// Runs password through check and then updates GUI   
function runPassword(strPassword, strFieldID)   
{   
   // Check password   
   var nScore = checkPassword(strPassword);   
     
   // Get controls   
   var ctlBar = document.getElementById(strFieldID + "_bar");   
   var ctlText = document.getElementById(strFieldID + "_text");   
   if (!ctlBar || !ctlText)   
   return;   
     
   // Set new width   
   ctlBar.style.width = nScore + "%";   

   // Color and text   
   // -- безупречный   
   if (nScore >= 90)   
   {   
   var strText = "отличный пароль! главное не забыть его :-)";   
   var strColor = "#0ca908";   
   }   
   // -- хороший   
   else if (nScore >= 80)   
   {   
   var strText = "хороший";   
   var strColor = "#00CCFF";   
   }   
   // -- довольно нормальный   
   else if (nScore >= 70)   
   {   
   var strText = "достаточно неплохо";   
   var strColor = "#5a74e3";   
   }   
   // -- нормальный   
   else if (nScore >= 50)   
   {   
   var strText = "нормально";   
   var strColor = "#FF6600";   
   }   
   // -- слабый   
   else if (nScore >= 25)   
   {   
   var strText = "слабенько";   
   var strColor = "#e7d61a";   
   }   
   // -- очень плохой   
   else   
   {   
   var strText = "ужас. qwerty и то лучше :-)";   
   var strColor = "#e71a1a";   
   }   
   ctlBar.style.backgroundColor = strColor;   
   ctlText.innerHTML = "<span style='color: " + strColor + ";'>" + strText + " - " + nScore + "%</span>";   
}   
     
// Checks a string for a list of characters   
function countContain(strPassword, strCheck)   
{   
   // Declare variables   
   var nCount = 0;   
     
   for (i = 0; i < strPassword.length; i++)   
   {   
   if (strCheck.indexOf(strPassword.charAt(i)) > -1)   
   {   
   nCount++;   
   }   
   }   
     
   return nCount;   
}   
</script>


Заработок для веб-мастеров
 
  • Страница 1 из 1
  • 1
Поиск:

Счетчик тИЦ и PR