Click here to Skip to main content
15,900,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, im new to php. I would like to create a password reset system.

1.User click 'forgot password'
2.User type username & email
3.user received email
4.user click link in the mail
5.user go to new page and type new password

everything go smooth, the problem is once user submit new password, nothing happen.


<?php 

if (isset($_POST['submit_pass'])) {
  $new_pass = mysqli_real_escape_string($db, $_POST['new_pass']);
  $new_pass_c = mysqli_real_escape_string($db, $_POST['new_pass_c']);


   $token =$_SESSION['token']);
    if (empty($new_pass) || empty($new_pass_c)) {array_push($errors, "Password is required");}
  if ($new_pass !== $new_pass_c) {array_push($errors, "Password do not match");}
  if (count($errors) == 0) {
  
    $sql = "SELECT * FROM password_resets WHERE token='$token' LIMIT 1";
    $results = mysqli_query($db, $sql) or trigger_error( "Query Failed!". mysqli_error($db));
    $email = mysqli_fetch_assoc($results)['username'];

    if ($email) {
      $new_pass = md5($new_pass);
      $sql = "UPDATE tutor SET password='$new_pass' WHERE tutor_username='$email'";
      $results = mysqli_query($db, $sql) or trigger_error( "Query Failed!". mysqli_error($db));
      header('location: ../st_login.php');
    }
  }

}
?>


What I have tried:

i had tried to change
$_SESSION
instead of
$_GET
or
$_REQUEST
Posted
Comments
Richard Deeming 4-Feb-19 14:29pm    
You really shouldn't still be using MD5 for password storage. It hasn't been secure for quite some time.

PHP has built-in methods which will give you a more secure hash:
PHP: password_hash[^]
PHP: password_verify[^]

(Glad to see someone who's not storing passwords in plain text, though. :) )

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900