PHP Forgot Password Function

后端 未结 12 871
后悔当初
后悔当初 2020-12-07 08:33

I have a small community website and I need to implement some sort of forgotten password function. I currently store the passwords in the DB, encrypted with MD5.

Is

12条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-07 09:06

    Write a page that accepts the md5 and email address as a get paramaeter and looks in the db for the email and md5'd password. Following Jared Cobb notes, that should get you on the right path. i just added some examples as well

    eg url to send http://yourdomain.com/resetpassword.php?code=md5codesentviaemail

     $code = isset($_GET['code']) ? $_GET['code'] : '';
        $email = isset($_GET['email']) ? $_GET['email'] : '';
    $checkPw = '';
    
        if(empty($code) || empty($email))
        {
         die();
        }
        $sqlQuery = 'SELECT * FROM users WHERE email = "'.$email.'";
    //remember to check for sql injections
        //then get the results as an array, i use a database class eg $user
    
        if(!empty($user['password']))
        {
         $checkPw = md5($user['password']);
        }else
        {
         die();
        }
    
        if($checkPw !== $code)
        {
         die();
        }else
        {
        //display form for user to change password
        }
    

    this should be sufficient enough for you to know that the user is a valid user and change his password

提交回复
热议问题