我試圖創建一個PHP的用戶名和密碼檢查,但不能讓它的工作,這裏是代碼:檢查用戶名和密碼,PHP
<?php
$servername = "iphere";
$user = "userhere";
$pass = "passwordhere";
$dbname = "databasehere";
try {
$username = $_GET['username'];
$password = $_GET['password'];
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $user, $pass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT username FROM users WHERE username = :name AND password = :password");
$stmt->bindParam(':name', $username);
$stmt->bindParam(':password', $password);
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
if($username == $result && $password == $result)
{
echo "OK";
}
else
{
echo "not OK";
}
}
catch(PDOException $e) {
echo "Error";
}
$conn = null;
?>
它不給任何錯誤或任何東西。它只是回聲好,那就是它。順便說一句,我用GET來做我的另一個項目。所以我稍後會改變它。
**危險**:「根本不哈希」是[不適合的哈希算法](http:// php達網絡/手動/ EN/faq.passwords.php);你需要[更好地照顧](https://www.owasp.org/index.php/Password_Storage_Cheat_Sheet)你的用戶密碼。 – Quentin
也許是'print_r($ result)'的時候了? –
從來沒有**永遠**以明文存儲密碼 – litelite