Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- include 'dbh.php';
- function cryptPass($input, $rounds = 9) {
- $salt = "";
- $saltChars = array_merge(range('A', 'Z'), range('a', 'z'), range(0, 9));
- for($i = 0; $i < 22; $i++) {
- $salt .= $saltChars[array_rand($saltChars)];
- }
- return crypt($input, sprintf('$2y$%02d$', $rounds).$salt);
- }
- $username = $_POST['username'];
- $password = $_POST['password'];
- $sql = "SELECT * FROM users WHERE username='$username'";
- $result = mysqli_query($conn, $sql);
- $row = mysqli_fetch_assoc($result);
- $hashedPassword = $row['password'];
- $hash = crypt($password, $hashedPassword);
- if($hash == $hashedPassword) {
- $_SESSION['userID'] = $row['userID'];
- $_SESSION['username'] = $row['username'];
- header("Location: index.php");
- } else {
- header("Location: login.php");
- }
- ?>
Add Comment
Please, Sign In to add comment