Guest User

Untitled

a guest
Jul 10th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.78 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Main index page
  4.  */
  5. require_once('lib/startup.php');
  6.  
  7. $vals = array('subd' => Local::$subd);
  8.  
  9.  
  10. if (!isset($_SESSION['user']))
  11. {
  12.     $tpl = 'index.twig';
  13.     $errors[] = 'You must be logged in to see this page.';
  14. }
  15. else
  16. {
  17.    $tpl = 'changepassword.twig';
  18.     //header('Location: changepassword.php');
  19.    
  20.     $user = $_SESSION['user'];
  21. }
  22.  
  23.  
  24. if (filter_has_var(INPUT_POST, 'oldpassword'))
  25. {
  26.     $errors = array();
  27.     $oldpass = array();
  28.    
  29.        
  30.     $oldpassword = md5(trim($_POST['oldpassword']));
  31.     $newpassword = md5(trim($_POST['newpassword']));
  32.     $newpassword1 = md5(trim($_POST['newpassword1']));
  33.    
  34.    
  35.     //check if they're empty, if not, continue
  36.     if ($oldpassword == '' || $newpassword == '' || $newpassword1 == '')
  37.     {
  38.         $errors[] = 'Please fill in all the boxes';
  39.    
  40.     }
  41.     else
  42.     {
  43.         $user = R::find('users', 'username=?' and 'password=?', array($_SESSION['user']->username, $oldpassword));
  44.     $userbean = R::load('users', $user['id']);
  45.        
  46.     if ($oldpassword != $userbean ->password)
  47.     {
  48.        $errors[] = 'Your old password is incorrect';
  49.     }  
  50.     if ($newpassword !== $newpassword1)
  51.     {
  52.         $errors[] = 'Your new passwords do not match';
  53.     }
  54.     //if (strlen ($newpassword) < 6)
  55.     //{
  56.        // $errors[] = 'Your new password must be 6 or more characters long.';
  57.     //}
  58.     $tpl = 'changepassword.twig';
  59.     }  
  60.    
  61.     if (!empty($errors))
  62.     {
  63.         $vals['errors'] = $errors;
  64.         $tpl = 'changepassword.twig';
  65.     }
  66.     else
  67.     {
  68.         //if it passes all the tests, dispense into the database
  69.         $userbean->password = ($newpassword);
  70.         R::store ($userbean);
  71.         //go back to members page page once dispensed.
  72.         $tpl = 'members.twig';
  73.     }
  74.            
  75. }
  76.    
  77.  
  78.  
  79.     echo $twig->loadTemplate($tpl)->render($vals);
  80. ?>
Add Comment
Please, Sign In to add comment