Guest User

asdfasdfa

a guest
Nov 25th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 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. $sql = "SELECT * FROM users WHERE username='$username'";
  19. $result = mysqli_query($conn, $sql);
  20. $row = mysqli_fetch_assoc($result);
  21.  
  22. $hashedPassword = $row['password'];
  23.  
  24. $hash = crypt($password, $hashedPassword);
  25. if($hash == $hashedPassword) {
  26. $_SESSION['userID'] = $row['userID'];
  27. $_SESSION['username'] = $row['username'];
  28. header("Location: index.php");
  29. } else {
  30. header("Location: login.php");
  31. }
  32.  
  33.  
  34. ?>
Add Comment
Please, Sign In to add comment