我用a password_verify检查我的哈希密码.我有PHP 5.5:
$this->db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
// if no connection errors (= working database connection)
if (!$this->db_connection->connect_errno) {
// escape the POST stuff
$user_name = $this->db_connection->real_escape_string($_POST['user_name']);
// database query, getting all the info of the selected user (allows login via email address in the
// username field)
$sql = "SELECT user_name, user_email, user_password_hash
FROM users
WHERE user_name = '" . $user_name . "' OR user_email = '" . $user_name . "';";
$result_of_login_check = $this->db_connection->query($sql);
// …Run Code Online (Sandbox Code Playgroud) 我正在学习 php,并正在尝试这个 php 函数,但由于某种原因,尽管尝试了这里的所有答案,但它仍然不起作用。我使用password_hash函数对'b'进行哈希处理并尝试验证它。这是我的代码
if(password_verify('b',
'$2y$10$OCZvoaVXX00xBkwpfGfgOu9AGXutvcZkhvpqSVWpL6v.BNnLsAN4u')){
echo "valid";
}else{
echo "invalid";
}
Run Code Online (Sandbox Code Playgroud)