this is my login.php page
<?php echo $loginError; ?>
<form class="form-inline" action="<?php echo htmlspecialchars( $_SERVER['PHP_SELF'] ); ?>" method="post">
<div class="form-group">
<label for="login-username" class="sr-only">Username</label>
<input type="text" class="form-control" id="login-username" placeholder="username" name="username">
</div>
<div class="form-group">
<label for="login-password" class="sr-only">Password</label>
<input type="password" class="form-control" id="login-password" placeholder="password" name="password">
</div>
<button type="submit" class="btn btn-default" name="login">Login!</button>
</form>
And this is the where I verify the password
if( isset( $_POST['login'] ) ) {
// build a function to validate data
function validateFormData( $formData ) {
$formData = trim( stripslashes( htmlspecialchars( $formData ) ) );
return $formData;
}
// create variables
// wrap the data with our function
$formUser = validateFormData( $_POST['username'] );
$formPass = validateFormData( $_POST['password'] );
// connect to database
include('connection.php');
// create SQL query
$query = "SELECT username, email, password FROM users WHERE username='$formUser'";
// store the result
$result = mysqli_query( $conn, $query );
// verify if result is returned
if( mysqli_num_rows($result) > 0 ) {
// store basic user data in variables
while( $row = mysqli_fetch_assoc($result) ) {
$user = $row['username'];
$email = $row['email'];
$hashedPass = $row['password'];
}
// verify hashed password with the typed password
if( password_verify( $formPass, $hashedPass ) ) {
// correct login details!
// start the session
session_start();
// store data in SESSION variables
$_SESSION['loggedInUser'] = $user;
$_SESSION['loggedInEmail'] = $email;
header("Location: profile.php");
} else { // hashed password didn't verify
// error message
$loginError = "<div class='alert alert-danger'>Wrong username / password combination. Try again.</div>";
}
} else { // there are no results in database
$loginError = "<div class='alert alert-danger'>No such user in database. Please try again. <a class='close' data-dismiss='alert'>×</a></div>";
}
// close the mysql connection
mysqli_close($conn);
}
?>
But the problem is that it is always return "Wrong password/username combination" .It seems that the problem is inside the password_verify() method. I have set the password at 255 VARCHAR and also my php version is 7.0.2