散列密码不匹配 - Laravel
Hashed Password not matching - Laravel
我正在使用 Laravel 4,我的数据库表/页面是使用旧版本 Laravel 创建的。版本3。我相信。
我有一个用户登录系统,当将散列密码从视图传递到控制器时,它与数据库的密码完全不匹配。
我的哈希代码是:
数据库
$wqCWqMgG7SRIukdyNEbXX.kK5c.8BxqzGVJSaCC55eKndFjqrJqJG
表格
y$hJQsF7.KkuXw4GYb8vk1o.SZhdocP7e8SxcjvBWjtLzpJPBlX0f5q
我的 Laravel 控制器代码是:
public function postLogin()
{
$email = Input::get('email');
$password = Hash::make(Input::get('Password'));
dd($password);
$credentials = array(
'user_email' => Input::get('UserName'),
'user_password' => Input::get('Password')
);
if(Auth::attempt($credentials))
{
return Redirect::to('dashboard')->with('message', 'You are now logged in!');
}
else
{
return Redirect::to('users/login')
->with('message', 'Your username/password combination was incorrect')
->withInput();
}
}
是不是旧版本的数据库不匹配?关于我可以检查/更改以匹配的内容的任何建议。
干杯
哈希不会 'match' 当你这样比较它们时。有一种盐被添加到所有哈希中。
问题很可能是您的数据库密码列名。如果它是 user_passwords
- 那么你必须在你的用户模型中设置它否则它不会工作(Laravel 将假定它是 password
否则)
所以你的 $credentials
必须使用 password
字段 - 而不是 user_password
$credentials = array(
'user_email' => Input::get('UserName'),
'password' => Input::get('Password')
);
如果您的用户数据库在名为 'password' 的列中有密码。然后你不需要做任何进一步的事情。但是,如果您的专栏名为 'user_password' - 那么您必须修改 User
模型和 add/modify 以下函数:
现在在用户模型(app/models/User.php)文件中你需要添加以下函数:
public function getAuthPassword() {
return $this->user_password;
}
同一秘密的新散列每次都会不同,因为在散列时添加了随机盐。要根据哈希值检查秘密,请使用:
Hash::check('secret', 'hash-of-secret');
Auth::attempt
失败的原因是传递的凭据始终需要有一个 password
密钥。 (即使您的数据库字段有不同的名称)
$credentials = array(
'user_email' => Input::get('UserName'),
'password' => Input::get('Password')
);
然后确保您的 User
模型实现了这个方法:
public function getAuthPassword()
{
return $this->user_password;
}
我正在使用 Laravel 4,我的数据库表/页面是使用旧版本 Laravel 创建的。版本3。我相信。
我有一个用户登录系统,当将散列密码从视图传递到控制器时,它与数据库的密码完全不匹配。
我的哈希代码是:
数据库
$wqCWqMgG7SRIukdyNEbXX.kK5c.8BxqzGVJSaCC55eKndFjqrJqJG
表格
y$hJQsF7.KkuXw4GYb8vk1o.SZhdocP7e8SxcjvBWjtLzpJPBlX0f5q
我的 Laravel 控制器代码是:
public function postLogin()
{
$email = Input::get('email');
$password = Hash::make(Input::get('Password'));
dd($password);
$credentials = array(
'user_email' => Input::get('UserName'),
'user_password' => Input::get('Password')
);
if(Auth::attempt($credentials))
{
return Redirect::to('dashboard')->with('message', 'You are now logged in!');
}
else
{
return Redirect::to('users/login')
->with('message', 'Your username/password combination was incorrect')
->withInput();
}
}
是不是旧版本的数据库不匹配?关于我可以检查/更改以匹配的内容的任何建议。
干杯
哈希不会 'match' 当你这样比较它们时。有一种盐被添加到所有哈希中。
问题很可能是您的数据库密码列名。如果它是 user_passwords
- 那么你必须在你的用户模型中设置它否则它不会工作(Laravel 将假定它是 password
否则)
所以你的 $credentials
必须使用 password
字段 - 而不是 user_password
$credentials = array(
'user_email' => Input::get('UserName'),
'password' => Input::get('Password')
);
如果您的用户数据库在名为 'password' 的列中有密码。然后你不需要做任何进一步的事情。但是,如果您的专栏名为 'user_password' - 那么您必须修改 User
模型和 add/modify 以下函数:
现在在用户模型(app/models/User.php)文件中你需要添加以下函数:
public function getAuthPassword() {
return $this->user_password;
}
同一秘密的新散列每次都会不同,因为在散列时添加了随机盐。要根据哈希值检查秘密,请使用:
Hash::check('secret', 'hash-of-secret');
Auth::attempt
失败的原因是传递的凭据始终需要有一个 password
密钥。 (即使您的数据库字段有不同的名称)
$credentials = array(
'user_email' => Input::get('UserName'),
'password' => Input::get('Password')
);
然后确保您的 User
模型实现了这个方法:
public function getAuthPassword()
{
return $this->user_password;
}