, , 32 , ,
, db
function genRandomString() {
$length = 32;
$characters = "0123456789abcdefghijklmnopqrstuvwxyz";
$string ="";
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, (strlen($characters))-1)];
}
return $string;
}
, php myAdmin, forget_passes, , ,
$key = genRandomString(); // assign random code
$assign = $db->query("INSERT INTO `YOUR_DB_NAME`.`forgotten_pass` (`email` ,`randomKey` , `time`)
VALUES ('$email', '$key', CURRENT_TIMESTAMP );");
, resetpassword.php(, , get, ,
www.yourdomain.com/pass_reset.php(ADD? secretkey = THE_GENERATED_HERE)
, , reset , - :
, , reset /
: http://www.yourdomain.com/pass_reset.php?secretKey=a12s236d5c8d4fkejus10a1s2d4c8741
, , sql, , , , :
<?php
if (isset($_GET['secretKey'])) {
$secretKey = $_GET['secretKey'];
$sql = 'select * from forgotten_pass WHERE email=$The_User_Email and randomKey='$secretKey'';
}
, , , , , .
:
if mysql_num_rows($sql)>0 { echo "Success, ";
?>
<form method="post" action="passupdate.php">
<input name="password" value =""/>
<input name"confirmedPassword" value=""/>
<input type="submit" value="Save my new password">
</form>
<?php
} else {
echo "Sorry, invalid reset link";
}