![]() |
|
|
#5 |
|
Архивный участник
Join Date: May 2005
Posts: 216
|
Change pass page
[hr:49134192da] [php:1:49134192da]<?php securitycheck($securitycheck); $error = 0; echo ' <script> function isAlphaNumeric(value) { if (value.match(/^[a-zA-Z0-9]+$/)) { return true; } else { return false; } } function checkform() { if(changepassword.oldpassword.value=="") { alert("Please enter your old password.") return false; } if(changepassword.newpassword.value=="") { alert("Please enter a new password.") return false; } if (!isAlphaNumeric(changepassword.newpassword.value) ) { alert("Your new password must be alphanumeric!"); return false; } if(changepassword.newpassword2.value=="") { alert("Retype your new password.") return false; } if(changepassword.oldpassword.value==changepasswor d.newpassword.value) { alert("Old password cannot be the same as new password.") return false; } return true; } </script> '; echopage('header', 'Change Password'); if($_POST['action']=='changepassword') { $error = 2; connectdb($CONFIG['dbdbname'], $CONFIG['dbaddress'], $CONFIG['dbuser'], $CONFIG['dbpass']); $username = $_COOKIE['user']; $oldpassword = $_POST['oldpassword']; $newpassword = $_POST['newpassword']; $newpassword2 = $_POST['newpassword2']; $username = antiinjection($username); $oldpassword = antiinjection($oldpassword); $newpassword = antiinjection($newpassword); $newpassword2 = antiinjection($newpassword2); echo "<div align=center>"; $result = mssql_query (sprintf(SELECT_USER_PASS, $username)); $rows=mssql_fetch_assoc($result); extract($rows); $password = '0x' . bin2hex($password); $oldpassword = encrypt($oldpassword); if ($password!=$oldpassword) { echo "Old password is incorrect. "; $error = 1; } if ((strlen($newpassword)<4 ||strlen($newpassword)>16) && $newpassword!="") { echo "Password length must be 4 to 16 characters long. "; $error = 1; } if ($newpassword!=$newpassword2) { echo "Retyped password is incorrect. "; $error = 1; } echo "</div>"; } if($error<2) { echo " <form name='changepassword' action='home.php?page=changepassword' method='post' onsubmit='return checkform()' autocomplete='off'> <table cellspacing=0 border=0 cellpadding=0 align=center> <tr> <td width=200> Old Password </td> <td> <div align=right> <input type=password maxlength=16 name=oldpassword> </div> </td> </tr> <tr> <td> New Password </td> <td> <div align=right> <input type=password maxlength=16 name=newpassword> </div> </td> </tr> <tr> <td> Retype New Password </td> <td> <div align=right> <input type=password maxlength=16 name=newpassword2> </div> </td> </tr> </table> <div align=center> <input type=hidden name=action value='changepassword'> <input type=submit name=submit value=' Submit '> </div> </form> "; } if($error==2) { $newpassword = encrypt($newpassword); mssql_query(sprintf(UPDATE_PASSWORD, $newpassword, $account)); echo ' <div align=center> Password has been successfully changed. You will be redirected to the login page in 3 seconds or you can click here. </div> '; delayedrefresh('logout.php'); } echopage('footer', ''); ?> [/php:1:49134192da] ~~~~~~~~~ credit: L2CP - Re-worked by FORT staff [hr:49134192da] Anti injection (put in functions) [hr:49134192da] [php:1:49134192da] <?php function antiinjection($str) { $banwords = array ("'", ",", ";", "--", " or ", ")", "(", " OR ", " and ", " AND ","/n","/r"); if ( eregi ( "[a-zA-Z0-9]+", $str ) ) { $str = str_replace ( $banwords, '', strtolower ( $str ) ); } else { $str = NULL; } [/php:1:49134192da] [hr:49134192da] An if it possible decrese the input lenght to 11 chars (no need to change this on sql database) |
|
|
| Thread Tools | Search this Thread |
| Display Modes | |
|
|