In my Login form, I try entering the values I inserted into the MySQL tables I connected with PHP, but no matter what values I enter into the input fields, I always get the error I set up when the Username and Password are incorrect:
die("The username or password is incorrect. Click <a href='http://growtapians.com/Login & Register System/index.php'>here</a> and try again.");
This is the code to the entire function when someone enters in their credentials in the Login form:
if ($_POST['login']) {
if ($_POST['username'] && $_POST['password']) {
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string(hash("sha512", $_POST['password']));
$user = mysql_fetch_array(mysql_query("SELECT * FROM 'users' WHERE 'Username' = '$username' && 'Password' ='$password'"));
if ($user == '0' || $user['Password'] != $password) {
die("The username or password is incorrect. Click <a href='http://growtapians.com/Login & Register System/index.php'>here</a> and try again.");
};
$salt = hash("sha512, rand() . rand() . rand()");
setcookie("c_user", hash("sha512", $username), time() + 24 * 60 * 60, "/");
setcookie("c_salt", $salt, time() + 24 * 60 * 60, "/");
$userID = $user['ID'];
mysql_query("UPDATE 'users' SET 'Salt'='$salt' WHERE 'ID'='$userID'");
die("You have logged in successfully, $username!");
};
};
The HTML:
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device, height=device=height, initial-scale=1'>
</head>
<body>
<div id='logindiv' style='width: 50%; padding: 10px; border: 5px solid #316ED6; background-color: #648CD1; color: #31D8EB; margin: auto; border-radius: 1.3em; text-align: center;'>
<h1>Login</h1>
<br />
<form action='' method='post'>
<div>
<b>Username:</b>
<input type='text' name='username' style='padding: 4px;'/>
</div>
<div>
<b>Password:</b>
<input type='password' name='password' style='padding: 4px; '/>
</div>
<div>
<input type='submit' value='Login' name='login'/>
</div>
</form>
<div>
<h4>No Account? Register <a href='register.php'>Here!</a></h4>
</div>
</div>
</body>
NOTES:
The PHP version supported by my hosting service is 5.5 & 5.6
I followed a tutorial dating 3 years back, so please excuse any outdated code
The extra bracket outside of the formatted code is supposed to be in the box of code I've provided, but it's not in there for some reason