为什么 laravel 密码不匹配?
Why laravel password not match?
我正在尝试登录,但总是失败。
这是我存储密码的方式
'password' => bcrypt($data['password']),
在laravel登录控制器中。
public function customchecker()
{
$credentials = [
'username' => Input::get('username'),
'password' => bcrypt(Input::get('password'))
];
if (Auth()->attempt($credentials)) {
return Redirect::to('home')->with('alert-success', 'You are now logged in.');
}else{
$errors = ['username' => ['Email and/or password invalid.']];
return Redirect::back()->withErrors($errors)->withInput(Input::except('password'));
}
}
我用这个测试
$credentials = [
'username' => Input::get('username'),
'password' => Input::get('password')
];
仍然无法正常工作,我该如何解决?
在凭据中你不应该 bcrypt 密码,你应该只传递纯文本密码,而不是:
$credentials = [
'username' => Input::get('username'),
'password' => bcrypt(Input::get('password'))
];
使用:
$credentials = [
'username' => Input::get('username'),
'password' => Input::get('password')
];
它会起作用。
在引擎盖下,稍后会完成类似这样的事情:
public function validateCredentials(UserContract $user, array $credentials)
{
$plain = $credentials['password'];
return $this->hasher->check($plain, $user->getAuthPassword());
}
如您所见,稍后将使用普通密码来比较密码是否有效。
我正在尝试登录,但总是失败。
这是我存储密码的方式
'password' => bcrypt($data['password']),
在laravel登录控制器中。
public function customchecker()
{
$credentials = [
'username' => Input::get('username'),
'password' => bcrypt(Input::get('password'))
];
if (Auth()->attempt($credentials)) {
return Redirect::to('home')->with('alert-success', 'You are now logged in.');
}else{
$errors = ['username' => ['Email and/or password invalid.']];
return Redirect::back()->withErrors($errors)->withInput(Input::except('password'));
}
}
我用这个测试
$credentials = [
'username' => Input::get('username'),
'password' => Input::get('password')
];
仍然无法正常工作,我该如何解决?
在凭据中你不应该 bcrypt 密码,你应该只传递纯文本密码,而不是:
$credentials = [
'username' => Input::get('username'),
'password' => bcrypt(Input::get('password'))
];
使用:
$credentials = [
'username' => Input::get('username'),
'password' => Input::get('password')
];
它会起作用。
在引擎盖下,稍后会完成类似这样的事情:
public function validateCredentials(UserContract $user, array $credentials)
{
$plain = $credentials['password'];
return $this->hasher->check($plain, $user->getAuthPassword());
}
如您所见,稍后将使用普通密码来比较密码是否有效。