I am building a login form which also supports hashing with salts.
I have completed the login form but in my login form, when user doesn't provide password, he is redirected to welcome page & when user submits password, error occurs saying incorrect password even though the submitted password is correct.
Below is my login form:
<?php
if (isset($_POST['login'])) {
$email = $_POST['email'];
$userPassword = $_POST['password'];
$query = "SELECT * FROM members WHERE (email='$email')";
$result = mysql_query($query) or die('mysql error');
if (mysql_num_rows($result) == 1) {
$get_user_details = mysql_fetch_array($result);
$user_id = strip_tags($get_user_details['user_id']);
$db_password = strip_tags($get_user_details['password']);
$salt = strip_tags($get_user_details['salt']);
$sr_user_sub_pass = hash('sha512', $userPassword . $salt);
if ($user_sub_pass == $db_password) {
header("location: welcome.php");
} else {
echo 'incorrect password';
}
} else {
echo 'user not found';
}
}
?>