我对密码哈希有问题。这是我的控制器
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
发布于 2015-06-29 08:07:53
每次生成不同的散列都是有意的,因为散列::make()方法将生成随机盐。为了安全地保护用户的密码,必须使用随机盐。
要根据存储的哈希检查输入的密码,可以使用Hash::check()方法,它将从散列值中提取使用过的salt,并使用它生成可比较的散列。
// 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);发布于 2015-06-29 07:22:00
这是因为如果您不给一个salt,bcrypt会在每次哈希时创建一个。
来源
https://stackoverflow.com/questions/31109661
复制相似问题