Created
June 22, 2019 11:25
-
-
Save dukesteen/668db062c8b1d0fd98133ed122a5169a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
?> | |
<?php | |
include_once 'C:\xampp\htdocs\personal-website-php\includes\dbh.inc.php'; | |
?> | |
<?php | |
if(isset($_POST['login_submit'])){ | |
$username = $_POST['login_username']; | |
$password = $_POST['login_password']; | |
$successUrl = "portal.php"; | |
$usernameEmpty = false; | |
$passwordEmpty = false; | |
if(empty($username)){ | |
echo "<span class='form-error'>Please enter your username</span>"; | |
$usernameEmpty = true; | |
} | |
elseif (empty($password)){ | |
echo "<span class='form-error'>Please enter your password</span>"; | |
$passwordEmpty = true; | |
} | |
else{ | |
$sql = "SELECT members_password FROM tbl_members WHERE members_username=:username;"; | |
// Create prepared statement | |
$stmt = $connection->prepare($sql); | |
// Prepare statement | |
$stmt->bindValue(':username', $username, PDO::PARAM_STR); | |
$results = $stmt->execute(); | |
if($results){ | |
$user = $stmt->fetch(); | |
if($user) { | |
$passwordVerify = password_verify($password, $user['members_password']); | |
if($passwordVerify == false){ | |
echo "<span class='form-error'>Login failed</span>"; | |
} | |
else { | |
$_SESSION['username'] = $username; | |
header("Location: https://www.google.com"); | |
exit; | |
} | |
} | |
} | |
else { | |
echo "<span class='form-success'>No account found, please register</span>"; | |
} | |
} | |
} | |
?> | |
<script> | |
$(".login-username, .login-password").removeClass("input-error"); | |
var errorUserEmpty = "<?php echo $usernameEmpty; ?>"; | |
var errorPwEmpty = "<?php echo $passwordEmpty; ?>"; | |
if(errorUserEmpty == true) { | |
$(".login-username").addClass("input-error"); | |
} | |
if (errorPwEmpty == true){ | |
$(".login-password").addClass("input-error"); | |
} | |
if(errorUserEmpty == false && errorPwEmpty == false){ | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment