Laravel 4 哈希::检查总是失败

Laravel 4 哈希::检查总是失败,laravel-4,Laravel 4,我在Linux和Windows上用Auth做过项目,从未遇到过哈希问题。它的基本要点是密码不会通过默认用户设置的Hash::check方法。我已经看过了关于SO的大多数答案,他们是典型的不理解Hash的用户,每次都会生成不同的值,或者Hash::check需要普通值,然后是数据库中用户的Hash值。起初,这是Auth::trust的失败,但进一步看似乎是一个哈希验证问题。我已经读了一遍又一遍,以确保我没有遗漏一些东西,比如确保db password字段太短(为了确定起见,将长度设置为256) 设

我在Linux和Windows上用Auth做过项目,从未遇到过哈希问题。它的基本要点是密码不会通过默认用户设置的Hash::check方法。我已经看过了关于SO的大多数答案,他们是典型的不理解Hash的用户,每次都会生成不同的值,或者Hash::check需要普通值,然后是数据库中用户的Hash值。起初,这是Auth::trust的失败,但进一步看似乎是一个哈希验证问题。我已经读了一遍又一遍,以确保我没有遗漏一些东西,比如确保db password字段太短(为了确定起见,将长度设置为256)

设置

用户模型

class User extends Eloquent implements UserInterface, RemindableInterface {
  protected $fillable = array(
    'email',
    'password',
  );

  protected $guarded = array(
  'id',
  );

  //add the UserInterface / RemindableInterface methods here
}
种子

User::create(array( //could also do DB insert way..
  'id'=>1,
  'email' => 'admin@example.com',
  'password' => Hash::make('admin'),
));

//User created with correct hash no problem.
测试柱路线

//some other validation above this. Email / password correctly passed from form
$email = Input::get('email');
$password = Input::get('password');

$user = User::where('email', $email)->first();
//gets user with hashed pass fine
$sucess = Hash::check( $password, $user->password ); //could do $user->getAuthPassword() as well
//always false..
//initially tried Auth::attempt getting the same results because of the internal Hash::check
尝试过

  • 我已经完成了验证,将带有salt的db散列与插入的普通过程进行了比较,在salt比较之后,插入的普通过程失败了
  • 我尝试过在get sign-in路由(如下)上创建一个新用户,并在表单上尝试这些凭据,但它仍然无法登录(我想这可能是一个种子问题)

    $newUser=新用户(数组)( '电子邮件'=>'admin2@example.com', 'password'=>Hash::make('test') )); $newUser->save()


在这一点上,在我不知道的情况下,这似乎是一个奇怪的密码验证/密码散列问题。

结果是在用户模型上设置了默认的setPasswordAttribute方法,它通过开始填充为任何创建或构造的用户运行

删除:

public function setPasswordAttribute( $value )
{
  $this->attributes['password'] = Hash::make( $value );
}

如果你
Hash::check('admin',Hash::make('admin'))
,效果会很好(返回true)。有一种情况我本来以为会失败,但仍然让我感到困惑。然后很可能
Input::get('password')
不是你想象的那样,或者
$user->password
不是。你在电子邮件上有唯一的索引吗?没有使用不同密码的重复电子邮件?在第二次散列密码的模型中,你有一个创建的监听器吗?结果发现有一个变异子我不得不深入挖掘。谢谢你的快速回顾。