Okay so I have this in my index.php
<form action="login.php" method="post">
<font >Username</font><br />
<input type="text" class="form-control" name="name" value="" style="width: 140px" />
<br />
<font >Password</font><br />
<input type="password" class="form-control" name="passwd" value="" style="width:140px"/>
<br /><br />
<input type="submit" value="Login" class="btn btn-primary"" style="width: 140px"/> </form>
The problem I'm having is, when the user logs in they're able to use any password and still proceed to the usercp.php so it's only checking the username, what part am I missing or have I done wrong? Much appreciation to any replies.
Additional info: My database has saved passwords in md5
Then this is in my login.php
*UPDAATE
I changed my code to;
<?php
require("common.php");
$submitted_name = '';
if(!empty($_POST))
{
$query = "
SELECT
name,
passwd
FROM users
WHERE
name = :name
";
$query_params = array(
':name' => $_POST['name']
);
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_passwd = md5( $_POST['passwd']);
if($check_passwd === md5($row['passwd']))
{
$login_ok = true;
}
} if($login_ok)
{
unset($row['passwd']);
$_SESSION['user'] = $row;
header("Location: usercp.php");
die("Redirecting to: usercp.php");
}
else
{
print("Login Failed.");
$submitted_name = htmlentities($_POST['name'], ENT_QUOTES, 'UTF-8');
}
}
?>
By changing
if($check_passwd = md5($row['passwd']))
to this
if($check_passwd === md5($row['passwd']))
I can't log in at all with the right or wrong password, i've also tried with x2 =
All help is very appreciated, thankyou!!