2012-01-14 4 views
2

누군가 제발 저를 도울 수 있는지 궁금합니다.비밀번호 재설정 링크 만료

저는 '비밀번호 재설정'프로세스에 대해 많은 조사를 해왔고 내가 찾은 자습서 중 하나에서이 기능을 제공하는 다음 코드를 함께 넣을 수있었습니다.

는 비밀번호

<?php 

// Connect to MySQL 
$c = mysql_connect("host", "user", "password"); 
mysql_select_db("database", $c); 

// Was the form submitted? 
if ($_POST["ForgotPasswordForm"]) 
{ 
    // Harvest submitted e-mail address 
    $emailaddress = mysql_real_escape_string($_POST["emailaddress"]); 

    // Check to see if a user exists with this e-mail 
    $userExists = mysql_fetch_assoc(mysql_query("SELECT `emailaddress` FROM `userdetails` WHERE `emailaddress` = '$emailaddress'")); 
    if ($userExists["emailaddress"]) 
    { 
       // Create a unique salt. This will never leave PHP unencrypted. 
       $salt = "KEY"; 

     // Create the unique user password reset key 
$password = md5($salt . $userExists["emailaddress"]); 


     // Create a url which we will direct them to reset their password 
     $pwrurl = "phpfile.php?q=" . $password; 

     // Mail them their key 
     $mailbody = "Dear user,\n\nIf this e-mail does not apply to you please ignore it. It appears that you have requested a password reset at our website \n\nTo reset your password, please click the link below. If you cannot click it, please paste it into your web browser's address bar.\n\n" . $pwrurl . "\n\nThanks,\nThe Administration"; 
     mail($userExists["emailaddress"], "", $mailbody); 
     echo "Your password recovery key has been sent to your e-mail address."; 
    } 
    else 
     echo "No user with that e-mail address exists."; 
} 

?> 

암호 재설정 내가 지금은 사용자에게 보내 링크의 시간 제한 만료를 추가 할

<?php 

// Connect to MySQL 
$c = mysql_connect("host", "user", "password"); 
mysql_select_db("database", $c); 

// Was the form submitted? 
if ($_POST["ResetPasswordForm"]) 
{ 
    // Gather the post data 
    $emailaddress = mysql_real_escape_string($_POST["emailaddress"]); 
    $password = md5(mysql_real_escape_string($_POST["password"])); 
    $confirmpassword = md5(mysql_real_escape_string($_POST["confirmpassword"])); 

    $q = $_POST["q"]; 

    $passwordhint = $_POST["passwordhint"]; 

    // Use the same salt from the forgot_password.php file 
    $salt = "KEY"; 

    // Generate the reset key 
    $resetkey = md5($salt . $emailaddress); 

    // Does the new reset key match the old one? 
    if ($resetkey == $q) 
    { 
     if ($password == $confirmpassword) 
     { 
      // Update the user's password 
      mysql_query("UPDATE `userdetails` SET `password` = '$password', `passwordhint` = '$passwordhint' WHERE `emailaddress` = '$emailaddress'"); 
      echo "Your password has been successfully reset."; 
     } 
     else 
      echo "Your password's do not match."; 
    } 
    else 
     echo "Your password reset key is invalid."; 
} 

?> 

를 잊으. 나는 Stackoverflow 커뮤니티와 많은 다른 사람들의 게시물을보고 있었지만, 내가 찾고있는 것을 찾을 수 없었다.

나는 누군가가 나를 도울 수 있었는지 궁금해했고, 내가 이것을 성취 할 수있는 방법에 대해 약간의 지침을 주었다.

감사합니다.

+0

모든 PHP 파일에 DB 연결 데이터가 실제로 있습니까? – ThiefMaster

+0

안녕하세요, 아니요, 스크립트를 정리하는 동안 사용하고 있습니다. 그런 다음 하나의 파일에서 작동하도록 변경됩니다. 친절한 대답 – IRHM

답변

1

암호 재설정이 요청 될 때 시간 소인을 사용하여 users 테이블에 필드를 추가하십시오. 키가 일치하는지 확인하면 타임 스탬프가 얼마나 오래된 지 확인하십시오.

이게 무슨 뜻이야?

+0

안녕하세요, 네,이게 내가 성취하려고하는 것입니다. 종류는 안부 – IRHM

0

내가하는 일은 사용자에게 보낸 해시와 사용자 테이블에서 생성 된 타임 스탬프를 모두 저장하는 것입니다.

리셋 페이지를 방문하면 다시 생성하지 않고 데이터베이스의 해시를 확인합니다 (이렇게하면 생성 된 방법을 기억할 필요가 없으므로이 방법으로 무작위 해시를 사용할 수 있습니다). 첫 번째 장소) 또한 타임 스탬프를 확인하십시오.

관련 문제