//index.php
<html>
<head>
<!--utf html5 declareren-->
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="cssreset.css">
</head>
<body>
<form action="login.php" method="POST">
username: <input type="text" name="usernamebox" required> <br>
password: <input type="password" name="passwordboxlogin" required> <br>
<input type="submit" value="Login">
</form>
<form action="register.php">
<input type="submit" value="Click here if you want to register">
</form>
</body>
</html>
//login.php
<?php
session_start();
error_reporting(E_ALL);
include ('connect.php');
$username = $_POST['usernamebox'];
$password = $_POST['passwordboxlogin'];
$_SESSION['usernamebox'] = $username;
//$db->query("SELECT * FROM `users` WHERE `username` = '$username'");
//
//$db->query("SELECT * FROM `users` WHERE `password` = '$password'");
//nieuw
$hash = "SELECT password FROM users WHERE username= '$username' ";
if (password_verify($password, $hash))
{
echo 'Password is valid!';
//header("Location: userpage.php");
}
else
{
echo 'Invalid password.';
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
</body>
</html>
我是一名IT學員,我似乎無法獲得此password_verify()
函數的工作。password_verify()不起作用
我基本上試圖將mysqli中的密碼哈希與login.php中POST表單中給出的密碼進行比較。密碼正確地散列到我的數據庫。
你實際上並沒有從數據庫中檢索密碼......你只是簡單地創建一個包含SQL查詢的字符串,但不會執行它;然後將該字符串與輸入的密碼 – 2015-04-03 16:13:33
的數據庫中的密碼進行比較是VARCHAR64 ...感謝Mark!生病試圖解決它 – Derikoe 2015-04-03 16:22:30