Advertisement
Guest User

Untitled

a guest
May 20th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. <?php
  2. session_start();
  3. $_SESSION["status"] = null;
  4. $_SESSION['userID'] = null;
  5.  
  6. if(isset($_POST['loginSubmit'])){
  7. $errors = array();
  8. include 'connect.php';
  9.  
  10. //Get entered information
  11. if(isset($_POST['login'])){
  12. $enteredLogin = $_POST['login'];
  13. }else{ $errors[] = "Enter a Username"; }
  14. if(isset($_POST['password'])){
  15. $enteredPass = $_POST['password'];
  16. }else{ $errors[] = "Enter a Password"; }
  17.  
  18. //if any error
  19. if(sizeof($errors) > 0){
  20. displayErrors($errors[]);
  21. }else{
  22. $row = $db->query("select * from Users where username='$enteredLogin'")->fetch();
  23. //If username isn't found
  24. if(sizeof($row) < 1){
  25. $errors[] = "Username not found";
  26. } else{
  27. //If password is correct
  28. if(password_verify($enteredPass, $row['Password'])){
  29. $_SESSION["Status"] = $row["UserType"];
  30. $_SESSION['UserID'] = $row['UserID'];
  31. header("location: homePage.php");
  32. }else{$errors[]="Incorrect Password";}
  33. }
  34. //Display any errors if you get here
  35. displayErrors($errors);
  36. }
  37. }
  38.  
  39. function displayErrors($errors){ ?>
  40. <div class='errors'>
  41. <ul><?php
  42. foreach($errors as $error){ ?>
  43. <li><?php echo $error ?></li><?php
  44. } ?>
  45. </ul>
  46. </div><?php
  47. }
  48. ?>
  49.  
  50. <DOCTYPE html>
  51. <html>
  52. <head>
  53. <title>ARTech Login</title>
  54. <link rel="stylesheet" style="text/css" href="artech.css">
  55. </head>
  56. <body>
  57. <div id='loginArea'>
  58. <form class='forms' action='artechLogin.php' method='post'>
  59. Username:<input type='text' name='login'>
  60. Password:<input type='password' name='password'>
  61. <input type='submit' value='Login' name='loginSubmit'>
  62. </div>
  63. </body>
  64. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement