MySQL database:[code]
mysql> SELECT * FROM login_data;
±—±---------±-----------------------------------------+
| id | username | password |
±—±---------±-----------------------------------------+
| 1 | foo | 62cdb7020ff920e5aa642c3d4066950dd1f01f4d |
±—±---------±-----------------------------------------+
1 row in set (0.00 sec)
[/code]
The password is SHA(‘bar’).
PHP code:
[php]
Logged In
<?php
$dbc = mysqli_connect(**********)
or die('
Error!
');
$user = $_POST['username'];
$pass = $_POST['password'];
$data = mysqli_query("SELECT * FROM login_data WHERE username = $user;",$dbc);
if(empty($data)) {
echo '
Sorry, that username is unregistered.
';
}
else {
$row = mysqli_fetch_array($data);
if($row['password'] == sha1($pass)) {
session_start();
$_SESSION = array();
$_SESSION['username'] = $user;
$_SESSION['user_id'] = $row['id'];
?>
<?php echo "You are now logged in as $user.
"; ?>
Back to Home
<?php
}
else { ?>
<?php echo "THe username $username and/or password were incorrect.
" ?>
Back Home
Back to the login page
<?php
}
mysqli_close($dbc);
}
?>
[/php]
Whenever I try to login with 'foo' and 'bar', the output is always "Sorry, that username is unregistered." What's wrong?