my problem is in the login page when the user login I get this error the sha256 function is not implement in mysql. Is there something wrong with my code or is is the sha2 not supported anymore. Is there other way to hash password in mysql.
Warning: hash(): Unknown hashing algorithm: sha2
create_account.php
//create account
$query = "INSERT INTO mytable (username,fname,lname,country,age,gender,password)
VALUES ('$username','$fname','$lname','$country',$age','$gender',SHA2('$password', 224))";
login.php
//check if password match
$hased_password= hash("sha2", $password);
$hased_password= mysqli_real_escape_string($conn,$hashedPass);
$query = mysqli_query($conn,"select * from mytable where password= '$hased_password' AND username='$username'");
$rows = mysqli_num_rows($query);
if ($rows == 1) {
$_SESSION['username']=$username;
$_SESSION['fname'] = $fname;
header("location: userPage.php");
} else {
$error = "username or password is invalid";
}
mysqli_close($conn);
password_hash()andpassword_verify()to manage passwords.hash("sha2", $password);before inserting record and pass the hash to the insert statement?sha2isn't a hashing algorithm, it's a family of algorithms. You need to pick something likesha256,sha512, etc and make sure you use the same bit length in both PHP and MySQL.