So im trying to make so the passwords the user enter will be encrypted when stored in my database. With BCRYPT im able to do that, however with the encryption now stored in the db the user cant login with their chosen password. Do anyone have any suggestions how i would go on about this?
Grateful for any kind of help!
Thanks in advance!
Register.php page below
<?php
require 'C:\wamp\www/projekt/connections.php';
if(isset($_POST['submit'])) {
session_start();
$fname = $_POST['firstname'];
$lname = $_POST['lastname'];
$uname = $_POST['username'];
$pwd = $_POST['password'];
$hashedpassword = password_hash($pwd, PASSWORD_DEFAULT);
$sql = $con->query("INSERT INTO users (FirstName, LastName, UserName, Password)VALUES('{$fname}', '{$lname}', '{$uname}', '{$hashedpassword}')");
if (password_verify($pwd, $hashedpassword)) {
header('Location: login.php');
}
}
?>
----------------------------------------------------------
login.php page below
<?php
$con = mysqli_connect("localhost","root","","userreg");
if(isset($_POST['login'])){
$uname = mysqli_real_escape_string($con,$_POST['Username']);
$pwd = mysqli_real_escape_string($con,$_POST['Password']);
$sel_user = "select * from users where UserName='$uname' AND Password='$pwd'";
$run_user = mysqli_query($con, $sel_user);
$check_user = mysqli_num_rows($run_user);
if($check_user>0){
$_SESSION['UserName']=$uname;
echo "<script>window.open('startpage.php','_self')</script>";
}
else {
echo "<script>alert('Username or password is not correct, try again!')</script>";
}
}
?>