gpt4 book ai didi

php - 在 Laravel 4.2 中,密码哈希每次都会产生不同的结果

转载 作者:行者123 更新时间:2023-12-05 09:21:37 25 4
gpt4 key购买 nike

我对密码散列有疑问。这是我的 Controller

 public function registerUser() {
$valid = Validator::make(Input::all(), array(
'pass' => 'required|min:5',
'pass2' => 'required|same:pass'
));

if($valid->fails()) {
return Redirect::route('register')->withErrors($valid)->withInput();
}
// $password = Input::get('pass');
if(Input::hasFile('photo')) {
$img = Input::file('photo');
if($img->isValid()) {
echo Hash::make(Input::get('pass'));
}else{
return Redirect::route('register')->withInput()->with('errorimg','image-error');
}
}else{
echo Hash::make(Input::get('pass'));
}

//return Redirect::route('register')->with('success','register-success');
}

每次我刷新浏览器时,散列的通行证总是在变化。

例如:如果我把“qwerty”作为通行证,它应该显示

$2y$10$PPgHGUmdHFl.fgF39.thDe7qbLxct5sZkJCH9mHNx1yivMTq8P/zi

最佳答案

每次生成不同的散列是有目的的,因为 Hash::make()方法将生成随机盐。需要随机加盐来安全地保护用户的密码。

要根据存储的哈希检查输入的密码,您可以使用方法Hash::check(),它会从哈希值中提取使用过的盐,并使用它来生成可比较的哈希.

// Hash a new password for storing in the database.
// The function automatically generates a cryptographically safe salt.
$hashToStoreInDb = Hash::make($password);

// Check if the hash of the entered login password, matches the stored hash.
// The salt and the cost factor will be extracted from $existingHashFromDb.
$isPasswordCorrect = Hash::check($password, $existingHashFromDb);

关于php - 在 Laravel 4.2 中,密码哈希每次都会产生不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31109661/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com