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

Php 在Laravel 4.2中,密码哈希每次都会产生不同的结果,php,hash,laravel-4,passwords,Php,Hash,Laravel 4,Passwords,我对密码哈希有问题。这是我的控制器 public function registerUser() { $valid = Validator::make(Input::all(), array( 'pass' => 'required|min:5', 'pass2' => 'required|same:pass' )); if($valid->fails()) { return Redirect::rou

我对密码哈希有问题。这是我的控制器

 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


这是因为如果你不给出一个
salt
bcrypt
每次它散列某个内容时都会创建一个


这是因为如果你不给出一个
salt
bcrypt
每次它散列某个内容时都会创建一个salt


每次生成不同的散列是故意的,因为该方法将生成一个随机salt。为了安全地保护用户的密码,必须使用随机密码

要根据存储的哈希值检查输入的密码,可以使用方法
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);

每次生成不同的散列是有意的,因为该方法将生成一个随机salt。为了安全地保护用户的密码,必须使用随机密码

要根据存储的哈希值检查输入的密码,可以使用方法
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);

你为什么认为这是个问题?Laravel没有正确的密码散列功能吗?如果不使用
password\u hash()
password\u verify()
。因为每次我输入'qwerty'作为密码,它总是生成不同的结果。您认为这是个问题吗?Laravel没有正确的密码散列功能吗?如果不使用
password\u hash()
password\u verify()
。因为每次我输入'qwerty'作为密码,它都会生成不同的结果。Auth::trunt()总是失败。它与您的答案一起工作,使用Hash::check()。。。Thankss martinI总是使用Auth::trunt()失败。它与您的答案一起工作,使用Hash::check()。。。谢谢马丁