Guest User

Untitled

a guest
Apr 15th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. <?php
  2. include_once dirname(dirname(dirname(__FILE__))) . "/const.php";
  3. include_once PHP_PATH . "../config1.php";
  4. // Logic to validate username / generate temporary password to reset it.
  5. if (isset($_POST ['cspwd_submit'])) {
  6.  
  7. $username = trim($_POST['uname']);
  8. $temp = trim($_POST['temp_password']);
  9. var_dump($temp);
  10. $newpass = trim($_POST['new_password']);
  11. $confirm = trim($_POST['con_password']);
  12.  
  13. //Check if the passwrod and confirm passwords are same
  14. if($newpass != $confirm){
  15. die("The password and new password does not match.");
  16. }
  17.  
  18. $temp = stripslashes($temp);
  19. $pass = stripslashes($newpass);
  20.  
  21. $pass = password_hash($pass, PASSWORD_DEFAULT);
  22.  
  23. if(empty($pass) || empty($username) || empty($temp)){
  24. die("Username and passwords cannot be left blank");
  25. }
  26.  
  27. $zero = 0;
  28.  
  29. $query = "select pk_staff_id, temp_password from tbl_staff where email = '$username' and active = '$zero'";
  30. var_dump($query);
  31. $stmt = $conn->prepare($query);
  32. $stmt->execute();
  33.  
  34. $res = [];
  35. $res = $stmt->fetch(PDO::FETCH_ASSOC);
  36.  
  37. if(empty($res['temp_password'])){
  38. die("The username does not exist.");
  39. }else{
  40. $hashed_password = $res['temp_password'];
  41. var_dump($hashed_password);
  42.  
  43. $pkid = $res['pk_staff_id'];
  44. if(password_verify($temp, $hashed_password))
  45.  
  46. {
  47. $active = 1;
  48. $query = "update tbl_staff set password = '$pass', temp_password = '', active = '$active' where pk_staff_id = '$pkid'";
  49. var_dump($query);
  50. $stmt = $conn->prepare($query);
  51. if($stmt->execute()){
  52. //Successful.
  53. header('location: ../../view/index.php');
  54. }else{
  55. die("Error: ". $stmt->errorInfo());
  56. }
  57.  
  58. }
  59. else{
  60. die("The temporary password does not match.");
  61. }
  62. }
  63. }
  64. ?>
Add Comment
Please, Sign In to add comment