Advertisement
scottk10

Untitled

Nov 21st, 2018
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. <?php
  2. ini_set("session.session_save_path", "/home/unn_w16040109/sessionData");
  3. session_start();
  4. require_once('functions.php');
  5. echo makePageStart();
  6. echo makeHeaderAndNav();
  7.  
  8. $username = filter_has_var(INPUT_POST, 'username') ? $_POST['username']: null;
  9. $username = trim($username);
  10. $password = filter_has_var(INPUT_POST, 'password') ? $_POST['password']: null;
  11. $password = trim($password);
  12.  
  13. if (empty($username) || empty($password)) {
  14. echo "<p> You need to provide both a username and password. Please try <a href='loginForm.php'>again</a>.</p>\n";
  15.  
  16. }
  17.  
  18. else{
  19. try{
  20. unset($_SESSION['username']);
  21. unset($_SESSION['logged-in']);
  22.  
  23. $dbConn = getConnection();
  24. $sqlQuery = "SELECT passwordHash FROM nmc_users WHERE username = :username";
  25. $stmt = $dbConn->prepare($sqlQuery);
  26. $stmt->execute(array(':username' => $username));
  27. $user = $stmt->fetchObject();
  28.  
  29. if ($user){
  30. if (password_verify($password, $user->passwordHash)){
  31. echo"<p> Logon has been a success!</p>\n";
  32. echo"<p> As a user you have access to the following page : </p>\n";
  33. echo"<a href='chooseRecordList.php'>Choose List Page</a>\n";
  34.  
  35. $_SESSION['logged-in'] = true;
  36.  
  37. $_SESSION['username'] = $username;
  38.  
  39. } else{
  40. echo "<p>The username or Password you entered were incorrect. Please try <a href='loginForm.php'>again</a>.</p>\n";
  41. }
  42. }else{
  43. echo "<p>The username or Password you entered were incorrect. Please try <a href='loginForm.php'>again</a>.</p>\n";
  44. }
  45.  
  46. } catch(expectation $e){
  47. echo "Record not found: " . $e->getMessage();
  48. }
  49.  
  50.  
  51. }
  52.  
  53.  
  54.  
  55. echo makeFooter();
  56. echo makePageEnd();
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement