Hi,
I've been trying and trying to add a few lines of code to my login script with no luck. What im trying to add is a activation code to check if the user has activated there account. Any help would be great thanks.
Login code:
require("db.php");
$submitted_username = '';
$errormessage = '';
if(!empty($_POST))
{
$query = "SELECT id,username,password,salt,actnum FROM users WHERE username = :username";
$query_params = array(
':username' => $_POST['username']
);
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
die("Failed to run query: " . $ex->getMessage());
}
$login_ok = false;
$row = $stmt->fetch();
if($row)
{
$check_password = hash('sha256', $_POST['password'] . $row['salt']);
if($check_password === $row['password'])
{
$login_ok = true;
}
}
if($login_ok)
{
unset($row['salt']);
unset($row['password']);
$_SESSION['user'] = $row;
header("Location: members");
die("Redirecting to: members");
}
else
{
$errormessage = 'Your user ID or password is incorrect.';
$submitted_username = htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8');
}
}
Activation code trying to add:
if ($row['actnum'] == '0'){
}
else
{
$errormessage = 'Please activate your account.';
}
And ways i have tried:
//This way works but this way has no error message to show so it shows $errormessage = 'Your user ID or password is incorrect.';
if($login_ok && $row['actnum'] == '0')
{
unset($row['salt']);
unset($row['password']);
$_SESSION['user'] = $row;
header("Location: members");
die("Redirecting to: members");
}
else
{
$errormessage = 'Your user ID or password is incorrect.';
$submitted_username = htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8');
}
//This way dont work at all
if ($row['actnum'] == '0'){
}
else
{
$errormessage = 'Please activate your account.';
}
if($login_ok)
{
unset($row['salt']);
unset($row['password']);
$_SESSION['user'] = $row;
header("Location: members");
die("Redirecting to: members");
}
else
{
$errormessage = 'Your user ID or password is incorrect.';
$submitted_username = htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8');
}