Advertisement
Guest User

Untitled

a guest
Jan 12th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. $username = $_POST['username'];
  2. $password = $_POST['password'];
  3. $username = stripslashes($username);
  4. $username = mysqli_real_escape_string($db, $username);
  5. $sql = "SELECT * FROM users WHERE username='$username'";
  6. $res = mysqli_query($db, $sql) or die(mysqli_error($db));
  7. if (mysqli_num_rows($res) > 0)
  8. {
  9. $row = mysqli_fetch_assoc($res);
  10. $hash = $row['password'];
  11.  
  12. }
  13. if (password_verify($password, $hash))
  14. {
  15. $_SESSION['username'] = $username; // Initializing Session
  16. header("location: $uri_cookie"); // Redirecting To Other Page
  17. $error = "Your username is: $username";
  18. $sql = "SELECT role FROM users WHERE username='$username'";
  19. $result = mysqli_query($db, $sql);
  20. $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
  21. if (mysqli_num_rows($result) == 1)
  22. {
  23. $_SESSION['role'] = $row['role'];
  24. $admin = $_SESSION['role'];
  25. echo "$admin";
  26. }
  27. }
  28. else {
  29.  
  30. $error = "Incorrect username or password.<br>".$hash. "<br>" .$password;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement