Guest User

Untitled

a guest
Oct 19th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. // Login
  2. <?php
  3.  
  4. session_start();
  5.  
  6. if (isset($_POST['login'])) {
  7.  
  8. $link = mysqli_connect('localhost', 'grinevich', 'OtGTqnHNR24SH2zA', 'events');
  9.  
  10. $user = mysqli_real_escape_string($link, trim($_POST['user_name']));
  11. $pwd = mysqli_real_escape_string($link, $_POST['user_password']);
  12.  
  13. if (empty($user) || empty($pwd)) {
  14. echo "Заполните все поля!";
  15. } else {
  16. $sql = "SELECT * FROM user WHERE user_name = '$user'";
  17. $result = mysqli_query($link, $sql);
  18. $resultCheck = mysqli_num_rows($result);
  19. if ($resultCheck < 1 ) {
  20. header("Location: /?login=notuser");
  21. exit();
  22. } else {
  23. if ($row = mysqli_fetch_assoc($result)) {
  24. // De - hashing password
  25. $hashedPassword = password_verify($pwd, $row['user_password']);
  26. if ($hashedPassword == false) {
  27. var_dump($row, $hashedPassword);
  28. //header("Location: /?login=notpassword");
  29. //exit();
  30. } elseif ($hashedPassword == true) {
  31. //Log int the user
  32. $_SESSION['u_id'] = $row['user_ID'];
  33. $_SESSION['u_name'] = $row['user_name'];
  34. $_SESSION['u_password'] = $row['user_password'];
  35. header("Location: /?login=success");
  36. exit();
  37. }
  38. }
  39. }
  40. }
  41.  
  42.  
  43. } else {
  44. header("Location: /");
  45. exit();
  46. }
  47.  
  48. ?>
Add Comment
Please, Sign In to add comment