Reputation: 75
I'm trying to check if account status is verified. This is done through a ENUM column in Mysql table. I've be able to change status to verified"yes" but cant seem to check if it is yes or no. I've tried different ways of the below code but to no avail. Thanks guys in advance.
<?php
ob_start();
session_start();
include '/home/wc002/include/dbconnect.php';
if (isset($_POST)) {
$username = strip_tags(trim($_POST['myusername']));
$password = strip_tags(trim($_POST['mypassword']));
$username = mysqli_real_escape_string($conn, $username);
// Register $myusername, $mypassword
$_SESSION["myusername"] = $username;
$_SESSION["mypassword"] = $password;
//Check if account is Verified
//$query ="SELECT Verified FROM Member WHERE Verified = false;";
//$check = mysqli_query($conn, $query);
//if ($check == true){
// echo "Please Verfiy your account";
//}
//else{
//Check username matches
$query1="SELECT `Password`, `salt` FROM `Member` WHERE `Username`='$username'";
$result1 = mysqli_query($conn, $query1);
if(mysqli_num_rows($result1) == 0) // User not found. So, redirect to TwitchMain.php again.
{
die(header("location:TwitchMain.php?loginFailed=true&reason=blank"));
}
$userData = mysqli_fetch_array($result1, MYSQL_ASSOC);
$hash = hash('sha256', $userData['salt'] . hash('sha256', $password));
//Incorrect password. So, redirect to TwitcMain.php again.
if($hash != $userData['Password'])
{
die(header("location:TwitchMain.php?loginFailed=true&reason=password"));
} else {
// Redirect to home page after successful login.
header('Location: Twitch.php');
}
}
?>
Upvotes: 0
Views: 198
Reputation: 1143
Add a condition to your readout, if your column name is 'ENUM', check after the success if ($userData['ENUM'] == 1).
if($hash != $userData['Password'])
{
die(header("location:TwitchMain.php?loginFailed=true&reason=password"));
} else {
// Redirect to home page after successful login.
if ($userData['Verified'] == 'YES'){
header('Location: Twitch.php');
} else {
die('account not activated');
}
}
Upvotes: 1