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'];
- $stmt = $conn->prepare('SELECT * FROM users WHERE username=?');
- $stmt->bind_param("s", $username);
- $stmt->execute();
- $result = $stmt->get_result();
- $row = $result->fetch_assoc();
- $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?loginFailed=true");
- }
- ?>
Add Comment
Please, Sign In to add comment