Guest User

process.php

a guest
Jan 16th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. <?php
  2. session_start();
  3. include 'dbh.php';
  4.  
  5. function cryptPass($input, $rounds = 9) {
  6. $salt = "";
  7. $saltChars = array_merge(range('A', 'Z'), range('a', 'z'), range(0, 9));
  8. for($i = 0; $i < 22; $i++) {
  9. $salt .= $saltChars[array_rand($saltChars)];
  10. }
  11. return crypt($input, sprintf('$2y$%02d$', $rounds).$salt);
  12. }
  13.  
  14.  
  15. $username = $_POST['username'];
  16. $password = $_POST['password'];
  17.  
  18. $stmt = $conn->prepare('SELECT * FROM users WHERE username=?');
  19. $stmt->bind_param("s", $username);
  20. $stmt->execute();
  21. $result = $stmt->get_result();
  22. $row = $result->fetch_assoc();
  23.  
  24. $hashedPassword = $row['password'];
  25.  
  26. $hash = crypt($password, $hashedPassword);
  27. if($hash == $hashedPassword) {
  28. $_SESSION['userID'] = $row['userID'];
  29. $_SESSION['username'] = $row['username'];
  30. header("Location: index.php");
  31. } else {
  32. header("Location: login.php?loginFailed=true");
  33. }
  34.  
  35.  
  36. ?>
Add Comment
Please, Sign In to add comment