Advertisement
Guest User

Untitled

a guest
Nov 26th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. <div class="container">
  2. <div class="row">
  3. <di class="col-md-4 col-md-offset-4">
  4. <fieldset>
  5. <legend>Login </legend>
  6. <form method="post" action="loginProcess.php">
  7. <div class="form-group">
  8. <label>User name:</label>
  9. <input type="text" name="username" class="form-control" required>
  10. </div>
  11. <div class="form-group">
  12. <label>Password:</label><input type="password" name="password" class="form-control" required>
  13. </div>
  14. <div class="form-group">
  15. <input type="submit" name="submit" value="Login" class="btn btn-default pull-right">
  16. </div>
  17. </form>
  18. </fieldset>
  19. </di>
  20. </div>
  21.  
  22.  
  23.  
  24. loginProcess.php
  25.  
  26. <?php
  27. session_start();
  28. include ("dbCon.php");
  29.  
  30.  
  31. $username = filter_has_var(INPUT_POST, 'username') ? $_POST['username']: null;
  32. $passWD = filter_has_var(INPUT_POST, 'password') ? $_POST['password']: null;
  33.  
  34. $sql = "SELECT passwordHash FROM te_users WHERE username = ?";
  35. $stmt = mysqli_prepare($conn, $sql);
  36.  
  37. mysqli_stmt_bind_param($stmt, "s", $username);
  38. mysqli_stmt_execute($stmt);
  39. mysqli_stmt_bind_result($stmt, $passWDHash); //Get the password hash from the query results for the given username and store it in the variable indicated
  40.  
  41. if(!empty($username)){
  42. if(!empty($passWD)){
  43. if (mysqli_stmt_fetch($stmt)) { //Check if a record was returned by the query.
  44. if (password_verify($passWD,$passWDHash)){
  45. $username = $_SESSION['username'];
  46. $login = $_SESSION['login'];
  47. $_SESSION['login'] = true;
  48. header("location:index.php");
  49. }
  50. else
  51. {
  52. echo "<p>Sorry, we don't seem to have that password.</p>";
  53. }
  54. }
  55. else {
  56. echo "<p>Sorry, we don't seem to have that username.</p>";
  57. }
  58. }
  59. else {
  60. echo "<p>Please enter the password.</p>";
  61. }
  62. }
  63. else {
  64. echo "<p>Please enter the username.</p>";
  65. }
  66.  
  67.  
  68. mysqli_stmt_close($stmt);
  69. mysqli_close($conn);
  70.  
  71. ?>
  72.  
  73.  
  74.  
  75.  
  76. otherpage.php
  77.  
  78. this is the code that use for authentication
  79.  
  80. if( empty($_SESSION['logged_in']) )
  81. {
  82. header('Location:login.php');
  83. exit;
  84. }
  85. else
  86. {
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement