Advertisement
Guest User

resetPassword.php

a guest
Apr 4th, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.95 KB | None | 0 0
  1. <?php
  2.     // Include configuration
  3.     require('include/config.php');
  4.    
  5.     // If logged in redirect to members page
  6.     if( $user->is_logged_in() ){ header('Location: welcome.php'); }
  7.    
  8.     $stmt = $db->prepare('SELECT resetToken, resetComplete FROM members WHERE resetToken = :token');
  9.     $stmt->execute(array(':token' => $_GET['key']));
  10.     $row = $stmt->fetch(PDO::FETCH_ASSOC);
  11.  
  12.     // If no token from db then kill the page
  13.     if(empty($row['resetToken'])){
  14.         $stop = 'Invalid token provided, please use the link provided in the reset email.';
  15.     } elseif($row['resetComplete'] == 'Yes') {
  16.         $stop = 'Your password has already been changed!';
  17.     }
  18.    
  19.     // If form has been submitted process it
  20.     if(isset($_POST['submit'])){
  21.        
  22.         // Basic validation
  23.         if(strlen($_POST['password']) < 3){
  24.             $error[] = 'Password is too short.';
  25.         }
  26.         if(strlen($_POST['passwordConfirm']) < 3){
  27.             $error[] = 'Confirm password is too short.';
  28.         }
  29.         if($_POST['password'] != $_POST['passwordConfirm']){
  30.             $error[] = 'Passwords do not match.';
  31.         }
  32.        
  33.         // If no errors have been created carry on
  34.         if(!isset($error)){
  35.            
  36.             // Hash the password
  37.             $hashedpassword = $user->password_hash($_POST['password'], PASSWORD_BCRYPT);
  38.            
  39.             try {
  40.                 $stmt = $db->prepare("UPDATE members SET password = :hashedpassword, resetComplete = 'Yes' WHERE resetToken = :token");
  41.                 $stmt->execute(array(
  42.                     ':hashedpassword' => $hashedpassword,
  43.                     ':token' => $row['resetToken']
  44.                 ));
  45.                
  46.                 // Redirect to index page
  47.                 header('Location: login.php?action=resetAccount');
  48.                 exit;
  49.             }
  50.             // Else catch the exception and show the error
  51.             catch(PDOException $e) {
  52.                 $error[] = $e->getMessage();
  53.             }
  54.         }
  55.     }
  56.    
  57.     // Include header template
  58.     require('layout/header.php');
  59.     // Include navigation template
  60.     require('layout/navigation.php');
  61. ?>
  62.        
  63.         <div id="navbarSpaceBottom"></div>
  64.        
  65.         <section id="about" class="bg-16 bg-cover bg-center">
  66.             <div class="bg-filter">
  67.                 <div class="container section-lg">
  68.                     <h1 class="top-title">Construction</h1>
  69.                 </div>
  70.             </div>
  71.         </section>
  72.        
  73.         <div class="container">
  74.             <div class="row">
  75.                 <div class="col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3">
  76.                     <p class="big-subtitle text-center">Test</p>
  77.                    
  78.                     <?php
  79.                         if(isset($stop)){
  80.                             echo "<p class'alert alert-danger'>$stop</p>";
  81.                         } else {
  82.                     ?>
  83.                        
  84.                         <form role="form" method="post" action="" autocomplete="off">
  85.                            
  86.                             <?php
  87.                                 // Check for any errors
  88.                                 if(isset($error)){
  89.                                     foreach($error as $error){
  90.                                         echo '<p class="alert alert-danger">'.$error.'</p>';
  91.                                     }
  92.                                 }
  93.                                
  94.                                 // Check the action
  95.                                 switch ($_GET['action']) {
  96.                                     case 'active':
  97.                                         echo "<h2 class='alert alert-success'>Your account is now active and you may now log in.</h2>";
  98.                                         break;
  99.                                     case 'reset':
  100.                                         echo "<h2 class='alert alert-success'>Please check your inbox for a reset link.</h2>";
  101.                                         break;
  102.                                 }
  103.                             ?>
  104.                            
  105.                             <div class="row">
  106.                                 <div class="col-xs-6 col-sm-6 col-md-6">
  107.                                     <div class="form-group">
  108.                                         <input type="password" name="password" id="password" class="form-control input-lg" placeholder="Password" tabindex="1">
  109.                                     </div>
  110.                                 </div>
  111.                                 <div class="col-xs-6 col-sm-6 col-md-6">
  112.                                     <div class="form-group ">
  113.                                         <input type="password" name="passwordConfirm" id="passwordConfirm" class="form-control input-lg" placeholder="Confirm Password" tabindex="2">
  114.                                     </div>
  115.                                 </div>
  116.                             </div>
  117.                             <hr>
  118.                            
  119.                             <div class="row">
  120.                                 <div class="col-xs-6 col-md-6">
  121.                                     <input type="submit" name="submit" value="Change Password" class="btn btn-primary btn-block btn-lg" tabindex="3">
  122.                                 </div>
  123.                             </div>
  124.                         </form>
  125.                        
  126.                     <?php } ?>
  127.                 </div>
  128.             </div>
  129.         </div>
  130.        
  131. <?php
  132.     // Include footer template
  133.     require('layout/footer.php');
  134. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement