Advertisement
Guest User

Login na stara sistema

a guest
Jan 24th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. if (LOGIN){
  2. $error = '';
  3. if (isset($_POST['login'])) {
  4. $username = strtolower(mysqli_real_escape_string($mysqli_server, $_POST['username']));
  5. $password = mysqli_real_escape_string($mysqli_server, $_POST['password']);
  6. function checkPassword($password, $db_password)
  7. {
  8. $parts = explode('$', $db_password);
  9. $salt = $parts[2];
  10. $hashed = hash('sha256', hash('sha256', $password) . $salt);
  11. $hashed = '$SHA$' . $salt . '$' . $hashed;
  12. return $hashed;
  13. }
  14. $sql = "SELECT * FROM `authme` WHERE username='$username'";
  15. $result = $mysqli_server->query($sql);
  16. if ($result->num_rows == '1') {
  17. while ($row = $result->fetch_assoc()) {
  18. $password = checkPassword($password, $row["password"]);
  19. $sql = "SELECT * FROM `authme` WHERE username='$username' AND password='$password'";
  20. $result = $mysqli_server->query($sql);
  21. if ($result->num_rows == '1') {
  22. while ($row = $result->fetch_assoc()) {
  23. $error = '<p class="highlighted"><span>Successful login.</span></p>';
  24. $_SESSION['store_username'] = $username;
  25. header('Location: ' . $_SERVER['REQUEST_URI']);
  26. }
  27. } else {
  28. $error = '<p class="highlighted"><span>Sorry!</span> Invalid password.</p>';
  29. }
  30. }
  31. } else {
  32. $error = '<p class="highlighted"><span>Sorry!</span> Invalid username.</p>';
  33. }
  34.  
  35. }
  36. exit;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement