The code below is a login system. The username is Administrator and the Password is Password (You can change it later on) what it does now is after the form is sent it just displays the login page. I cant find anything wrong with it. Please help. The error_log file shows nothing. It might be the password not hashing correctly. As I set the password using
echo password_hash("password", PASSWORD_DEFAULT);
and just inserting the result.
<?php
session_start();
$message="";
require 'settings.php';
if(count($_POST)>0) {
$username = mysqli_real_escape_string($_POST['user_name']);
$password = mysqli_real_escape_string($_POST['password']);
$result = mysqli_query("SELECT * FROM members WHERE username='" . $username . "'");
$row = mysqli_fetch_array($result);
if(is_array($row)) {
$hash = $row['password'];
$passwordcheck = password_verify($password, $hash);
}
if($hash == $passwordcheck){
$_SESSION["user_id"] = $row['id'];
$_SESSION["user_name"] = $row['username'];
} else {
$message = "Invalid Username or Password!";
}
if(isset($_SESSION["user_id"])) {
mysqli_query("DELETE * FROM LoginAttempts WHERE IP='".$ip."'");
header("Location:dashboard.php");
}
}
?>
<div class="panel-body">
<form name="frmUser" method="post" action="">
<fieldset>
<div class="form-group">
<input class="form-control" placeholder="Username" name="user_name" type="username" autofocus>
</div>
<div class="form-group">
<input class="form-control" placeholder="Password" name="password" type="password" value="">
</div>
<input type="submit" name="submit" value="Submit" class="btn btn-success btn-lg btn-block">
</fieldset>
</form>
<?php
if($locked == 'yes'){
echo "Sorry you are locked out of the system. Please try again in";
echo $timeleft;
}
?>
</div>
Edit: Now I get these errors: [15-Nov-2015 07:00:58 Europe/Moscow] PHP Warning: mysqli_connect(): (28000/1045): Access denied for user 'laughin1'@'176.31.10.37' (using password: NO) in /home/laughin1/public_html/admin/index.php on line 9 [15-Nov-2015 07:00:58 Europe/Moscow] PHP Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in /home/laughin1/public_html/admin/index.php on line 10 [15-Nov-2015 07:00:58 Europe/Moscow] PHP Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in /home/laughin1/public_html/admin/index.php on line 11 [15-Nov-2015 07:00:58 Europe/Moscow] PHP Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in /home/laughin1/public_html/admin/index.php on line 12 [15-Nov-2015 07:00:58 Europe/Moscow] PHP Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /home/laughin1/public_html/admin/index.php on line 14 [15-Nov-2015 07:00:58 Europe/Moscow] PHP Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/laughin1/public_html/admin/index.php on line 15
BUT if I change the MySQLi To MySQL everything is fine.