我有一個腳本代碼來登錄。將sha1更改爲password_hash不工作
不幸的是,這個使用sha1
不再推薦。我試圖將其更改爲password_hash()
,但它失敗了。
原始
public static function create($username, $password)
{
$q = self::$db->prepare('INSERT INTO user(username, password, email) VALUES (:username, :password, :email)');
return $q->execute(array(
':username' => $username,
':password' => sha1($password),
':email' => $email,
));
}
編輯
public static function create($username, $password)
{
$q = self::$db->prepare('INSERT INTO user(username, password, email) VALUES (:username, :password, :email)');
$new_password = password_hash($password, PASSWORD_DEFAULT);
return $q->execute(array(
':username' => $username,
':password' => $new_password,
':email' => $email,
));
}
這有什麼錯呢?
你得到的錯誤是什麼? –
它會拋出任何錯誤嗎? – phaberest
@Norax。請做一個你的PHP的版本檢查http://php.net/manual/en/function.password-hash.php – rahul