I'm using mysqli with hashpassword. I can't log in using my password and I don't know why. I tried all my best but its not working at all.
I'm using utf8 in my database.
This is my regiter php
<?php
if(isset($_POST["register"])){
if(!empty($_POST['name']) &&
!empty($_POST['studno']) &&
!empty($_POST['password']) &&
!empty($_POST['cpassword']) &&
!empty($_POST['email']))
{
$name=$_POST['name'];
$studno=$_POST['studno'];
$password= password_hash($_POST['password'],PASSWORD_BCRYPT);
$email=$_POST['email'];
$con=mysqli_connect('localhost','root','') or die(mysqli_error($con));
mysqli_select_db($con,'inventory') or die("cannot select DB");
$query=mysqli_query($con,"SELECT * FROM users WHERE studno='".$studno."'");
$numrows=mysqli_num_rows($query);
if($numrows==0) {
$sql = "INSERT INTO users(name,studno,email,password) "
. " VALUES('$name','$studno','$email','$password')";
$result=mysqli_query($con,$sql);
if ($_POST['password'] == $_POST['cpassword']) {
if ($result) {
header("Location: index.php?registered=1");
}
} else {
header("Location: signup.php?passwordnotmatch=1");
}
} else { /* numrows != 0 */
header("Location: signup.php?alreadyinuse=1");
}
} else {
header("Location: signup.php?allfieldisrequired=1");
}
}
?>
this is my log in php.
<?php
if (isset($_POST["login"])) {
if (!empty($_POST['studno']) && !empty($_POST['password'])) {
$studno=$_POST['studno'];
$password=$_POST['password'];
$con=mysqli_connect('localhost','root','') or die(mysql_error($con));
mysqli_select_db($con,'inventory') or die("cannot select DB");
$query=mysqli_query($con,"SELECT * FROM users WHERE studno='".$studno."' AND password='".$password."'");
$numrows=mysqli_num_rows($query);
if ($numrows!=0) {
while($row=mysqli_fetch_assoc($query)) {
$dbstudno=$row['studno'];
$dbpassword=$row['password'];
}
if ($studno == $dbstudno && password_verify($dbpassword,$row['password']))) {
session_start();
$_SESSION['sess_user']=$studno;
/* Redirect browser */
header("Location: home.php");
}
} else {
header("Location: index.php?error=1");
}
} else {
header("Location: index.php?missing=1");
}
}