我已經創建了一個登錄系統,它使用戶能夠使用先前定義的電子郵件和密碼登錄,但是在測試部分中,我注意到密碼錶示它們不匹配儘管我知道他們是正確的,因爲我在測試時寫下了測試結果。我似乎明白爲什麼發生這種情況,我認爲這可能是一些與我的密碼散列的,但我不知道what.The登錄頁面檢查是從文檔的login.php:PHP登錄系統密碼不匹配
if(empty($errors))
{
$sql = "SELECT accountID, password FROM users WHERE emails=?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$data['email']]);
if(!$row = $stmt->fetch())
{
// email didn't match
$errors['login'] = "Login failed. on email";
}
else
{
// email matched, test password
if(!password_verify($data['password'],$row['password']))
{
// password didn't match
$errors['login'] = "Login failed. on password";
}
else
{
// password matched
$_SESSION['user_id'] = $row['accountID'];
header('location: welcome.php');
die;
}
}
}
插入到數據庫散列,從insert.php:
if (isset($_POST['name'])){
$name = $_POST['name'];
}
if (isset($_POST['email'])){
$email = $_POST['email'];
}
if (isset($_POST['password'])){
$pword = $_POST['password'];
}
if (isset($_POST['busName'])){
$busName = $_POST['busName'];
}
if (empty($name)){
echo("Name is a required field");
exit();
}
if (empty($email)){
echo ("email is a required field");
exit();
}
if (empty($pword)){
echo("You must enter a password");
exit();
}
$pword = password_hash($pword, PASSWORD_DEFAULT)."/n";
//insert html form into database
$insertquery= "INSERT INTO `cscw`.`users` (
`accountID` ,
`businessName` ,
`name` ,
`emails` ,
`password`
)
VALUES (
NULL , '$busName', '$name', '$email', '$pword'
);";
和網頁我從login.php中所示的「登錄失敗的密碼。」如果您需要查看更多代碼,請告訴我。
'$ data'從哪裏來? –
在你的password_hash行中放一下'。「/ n」' – Yolo
@FrankM $ data = array_map('trim',$ _ POST); – trezremay