Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (!($user -> LoggedIn()))
- {
- if (isset($_POST['loginBtn']))
- {
- $username = $_POST['username'];
- $password = $_POST['password'];
- $errors = array();
- if (!ctype_alnum($username) || strlen($username) < 4 || strlen($username) > 15)
- {
- //$errors[] = 'Username Must Be Alphanumberic And 4-15 characters in length';
- }
- if (empty($username) || empty($password))
- {
- $errors[] = 'Please fill in all fields';
- }
- if (empty($errors))
- {
- $SQLCheckLogin = $odb -> prepare("SELECT COUNT(*) FROM `users` WHERE `username` = :username AND `password` = :password");
- $SQLCheckLogin -> execute(array(':username' => $username, ':password' => SHA1($password)));
- $countLogin = $SQLCheckLogin -> fetchColumn(0);
- if ($countLogin == 1)
- {
- $SQLGetInfo = $odb -> prepare("SELECT `username`, `ID`, `status` FROM `users` WHERE `username` = :username AND `password` = :password");
- $SQLGetInfo -> execute(array(':username' => $username, ':password' => SHA1($password)));
- $userInfo = $SQLGetInfo -> fetch(PDO::FETCH_ASSOC);
- if ($userInfo['status'] == 0)
- {
- $logAddr = $odb->prepare("INSERT INTO `login_history` (`username`,`ip`,`date`,`http_agent`) VALUES (:user, :ip, UNIX_TIMESTAMP(NOW()), :agent);");
- $logAddr->execute(array( ":user" => $username, ":ip" => $_SERVER['REMOTE_ADDR'], ":agent" => $_SERVER['HTTP_USER_AGENT']));
- $_SESSION['username'] = $userInfo['username'];
- $_SESSION['email'] = $userInfo['email'];
- $_SESSION['ID'] = $userInfo['ID'];
- echo '<script>swal("Success!", "You will get redirected!", "success")</script><meta http-equiv="refresh" content="1;url=index.php">';
- }
- else
- {
- echo '<script>swal("ERROR!", "Your account has been suspended!", "error")</script>';
- }
- }
- else
- {
- echo '<script>swal("ERROR!", "Login Failed!", "error")</script>';
- }
- }
- else
- {
- echo '<script>swal("ERROR!", ';
- foreach($errors as $error)
- {
- echo '"'.$error.'"';
- }
- echo ', "error")</script>';
- }
- }
- }
- else
- {
- header('location: index.php');
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement