I've created simple registration and login page. The problem occurs when i encrypt the password to store in db, I cant login with the same details i registered with. I've tried to store the password without encrypt it and its works just fine
signin-engine.php
if(isset($_POST['login'])){
$username = $_REQUEST["username"];
$pass = $_REQUEST["pass"];
//$encrypted = password_hash($pass , PASSWORD_BCRYPT);
$query = "SELECT * FROM account_detail
WHERE username = '$username'
AND password = '$pass'";
$result = mysqli_query($conn, $query);
if(mysqli_num_rows($result)>0){
header('location:status.php');
} else {
?>
<script>
alert('Your account has not been registered. Please register an account first.');
location='register.html';
</script>";
<?php
}
}
register-engine.php
<?php
include 'conn/conn.php';
if(isset($_POST['register'])){
$username = $_REQUEST['username'];
$pass = $_REQUEST['pass'];
//$encrypted = password_hash($pass , PASSWORD_BCRYPT);
$sql = "INSERT INTO account_detail
(`username`, `password`)
VALUES ('$username', '$pass')";
if($conn->query($sql) === TRUE) {
?>
<script>
alert('Your registration have been accepted');
location = 'index.html';
</script>
<?php
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}else {
?>
<script>
alert('Password didnt match, please try again');
location = 'register.html';
</script>
<?php
}
$conn -> close();
?>