Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2016
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. <?php
  2. include ("myConn.php");
  3. session_start();
  4.  
  5. if(isset($_POST['submit'])){
  6. $error = '';
  7. //username and password sent from Form, and trimmed for whitespace
  8. $uname = trim($_POST['username']);
  9. $pwd = trim($_POST['password']);
  10.  
  11. if($uname == '')
  12. $error .= '<b>Username:</b> Please enter a Username<br>';
  13.  
  14. if($pwd == '')
  15. $error .= '<b>Password</b> Please enter a Password<br>';
  16.  
  17. if($error == ''){
  18. $query = $db->prepare('SELECT id,username,password FROM students WHERE username = :username');
  19. $query->bindParam(':username', $uname);
  20. $query->execute();
  21. $result = $query->fetch(PDO::FETCH_ASSOC);
  22.  
  23. if($result === false){
  24. $error .= '<b>Username</b> or <b>Password</b> are not found<br>';
  25. } else {
  26. $validpwd = password_verify($pwd, $result['password']);
  27. if($validpwd){
  28. $_SESSION['user_id'] = $result['id'];
  29. header('location: homepage.php');
  30. exit;
  31. }
  32. }
  33.  
  34. /*if($result->num_rows > 0 && password_verify($pwd, $result['password'])){
  35. $_SESSION['username'] = $result['username'];
  36. header('location: homepage.php');
  37. exit;
  38. } else {
  39. $error .= '<b>Username</b> or <b>Password</b> are not found<br>';
  40. }*/
  41. }
  42. }
  43.  
  44.  
  45. ?>
  46.  
  47. <!DOCTYPE html>
  48. <html>
  49. <head>
  50. <link rel="stylesheet" type="text/css" href="style.css" />
  51. <form action="index.php">
  52. <button type="submit" class="logbutton" value="back">Go Back</button>
  53. </form>
  54.  
  55. <div class="logintitle">
  56. <h1>Login</h1>
  57. </div>
  58. </head>
  59.  
  60. <br><br>
  61. <body>
  62. <div class= "page">
  63. <div class="regbox">
  64. <br>
  65. <form action="" method="post">
  66. <label for 'username'>Username: </label>
  67. <input type="text" id="username" name="username" maxlength="20" placeholder="Client1" pattern="^(?=.*[A-Za-z])[A-Za-z\d]{4,}$" title="Four characters or numerics + no special characters" autofocus required />
  68. <br><br>
  69. <label for 'password'>Password: </label>
  70. <input type="password" id="password" name="password" maxlength="20" pattern="^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{6,}$" title="Contain six characters + one numeric" required />
  71. <br><br><br>
  72. <button type="submit" class="logbutton" value="submit" name="submit">Submit</button>
  73. <br><br>
  74. </form>
  75. </div>
  76. <br><br>
  77. <div class="errorbox">
  78. <?php
  79. if(isset($error)){
  80. echo ''.$error.'';
  81. }
  82. ?>
  83. </div>
  84.  
  85. </div>
  86. </body>
  87. <footer>
  88. </footer>
  89. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement