1
我正在開發iOS應用程序的登錄系統。在PHP中使用password_verify
這是我使用的發送JSON響應到應用程序的PHP腳本的一部分:
if(isset($_POST['correo']) && isset($_POST['pass']) && $_POST['key'] == "123456")
{
$password = $_POST['pass'];
$q = mysqli_query($mysqli,"SELECT * FROM users WHERE email = '".$_POST['correo']."' AND
encrypted_password = '".$_POST['pass']."'") or die (mysqli_error());
if(mysqli_num_rows($q) >= 1){
$r = mysqli_fetch_array($q);
// this is the hash of the password in above example
$hash = $r['encrypted_password'];
if (password_verify($password, $hash)) {
$results = Array("error" => "1","mensaje" => "su ID es ".$r['id'],"nombre" => $r['nombre'],"apellidos" => $r['apellidos'],"email" => $r['email'],
"imagen" => $r['imagen'],"unidad" => $r['unidad']);
} else {
$results = Array("error" => "2","mensaje" => " acceso denegado ");
}
}else{
$results = Array("error" => "3","mensaje" => "no existe");
}
}
echo json_encode($results);
我的問題是關於在PHP中使用password_verify。 我想知道它是否應該像在腳本中一樣工作,那麼應用程序中不會收到JSON響應。
謝謝
您mysqli_query總會回報空結果,因爲你傳遞查詢未加密的值並試圖使其等於加密'encrypted_password ='「。$ _ POST ['pass']' – diavolic
請參數化您的查詢。 – chris85
您最初是如何存儲用戶密碼的? 'encrypted'!='hahsed'(它應該被散列)。 – chris85