1

これに関連する他の質問/回答を見て、回答に合わせてコードを複数の方法で変更しようとしましたが、成功しませんでした。正常に機能する登録フォームがあり、password_hash 関数を使用してユーザーをデータベースに正常に追加します。パスワード フィールドは VARCHAR(255) で、入力するとハッシュ化されて表示されます。

問題はログインフォームにあります。私は一日中さまざまな方法を試しましたが、成功しませんでした。以下は私の現在の login.php スクリプトです。

<?php

 session_start(); // Starting Session

$error=''; // Variable To Store Error Message

if (isset($_POST['submit'])) {

//error if both boxes empty
if (empty($_POST['email']) || empty($_POST['password'])) {
$error = "Please fill in both boxes";
}
else
{

// connecting, selecting database
require_once 'dbstuff.php';
include 'opendb.php';

// To protect MySQL injection for Security purpose and  define $email and $password
$email = mysqli_real_escape_string($cxn,$_POST['email']);
$password = mysqli_real_escape_string($cxn,$_POST['password']);


//selects user = to email given
$sel_user = "SELECT * from Customer WHERE email='$email'";

$result = $cxn->query($sel_user);

//if matched email in DB verifies password given with hashed password in DB
if($result->num_rows ===1){
$row = $result->fetch_array(MYSQLI_ASSOC);
if (password_verify($password, $row['password'])){

    echo "match";
//$_SESSION['login_user']=$email; // Initializing Session
//header("location: index.php"); // Redirecting To Other Page
} else {
$error = "email or Password is invalid";
}
}
mysqli_close($cxn); // Closing Connection
}
}

?>

$error 変数は問題なく動作しますが、password_verify のどこが間違っているのかまだわかりません。「一致」ではなく「メールまたはパスワードが無効です」というエラーが表示され続けます。

コードで見逃していたものについて、フィードバックをいただければ幸いです。ありがとう :)

4

0 に答える 0