【发布时间】:2016-04-15 15:28:46
【问题描述】:
我刚开始使用 laravel 5,我正在做一个简单的登录功能来检查用户传递的电子邮件和密码是否与存储在数据库中的电子邮件和密码匹配。我一直在阅读文档 ([https://laravel.com/docs/5.0/hashing1) 但Hash::check($content['password'], $user->{'password'}) 总是返回 false。我的代码如下所示。
当我创建一个新用户时,我会像这样散列密码:
$content = json_decode($request->getContent(), true);
$user -> password = Hash::make($content['email']);
我的登录功能是这样的:
public function login(Request $request)
{
$content = json_decode($request -> getContent(), true);
$user = DB::table('users')->where('email', $content['email'])->first();
if (Hash::check($content['password'], $user->{'password'}))
{
// Redirect to dashboard
}
}
提前致谢!!
【问题讨论】:
-
你试过把
if (Hash::check($content['password'], $user->{'password'}))改成if (Hash::check($content['password'], $user->password))吗? -
我得到了同样的结果...
-
@IcarKwon 我希望我的回答能解决这个问题:)
标签: laravel authentication laravel-5