我有一個php(symphony)web應用程序和一個訪問同一數據庫的android應用程序。表中的密碼字段使用Bcrypt與交響樂加密,其值開始於$2y$13
,我用這個代碼的PHP加密我的密碼在Android應用程序中輸入:
if(isset($_POST['password'])){
$password = $_POST['password'];
$pas_hash= password_hash("$password", PASSWORD_BCRYPT);
$sql = 'SELECT * FROM tbl_auth WHERE password = :pas_hash';
$stmt = $conn->prepare($sql);
$stmt->bindParam(':pas_hash', $pas_hash, PDO::PARAM_STR);
$stmt->execute();
if($stmt->rowCount())
{
$result="true";
}
elseif(!$stmt->rowCount())
{
$result="false";
}
// send result back to android
echo $result;
}
的問題是,pas_hash
值開始$2y$10
,當我用password_verify()
,這個函數返回true
結果。 我沒有什麼問題,因爲發送到我的Android應用程序的最終$result
是false
。 謝謝。
我沒有看到你使用'password_verify'在一切,儘管說。那是你的問題。 –
這不是一個加密,它是一個散列。 –
你也在使用錯誤的方法 –