【发布时间】:2018-01-29 02:41:08
【问题描述】:
我正在尝试在 laravel 5.4 中对用户进行身份验证,使用尝试()我能够对用户进行身份验证,但我还想检查用户是否处于活动状态,并根据用户是否处于非活动状态显示自定义消息然后不同的消息,如果用户名密码不同,则不同的消息。
我的验证码:
public function checklogin(Request $request)
{
$password = bcrypt($request->password);
$userData = User::where('email',$request->email)->where('password',$password)->first();
if($userData!=NULL)
{
$credentials=array('email' => $request->input('email'),'password' => $request->input('password'),'status' => 'active');
if(Auth::guard('users')->attempt($credentials))
return redirect()->intended('/dashboard');
else
{
Mail::to($request->email)->send(new VerifyUser($userData));
return redirect('/')->with('error','Your account is unverified - check your email for account verification link');
}
}
else
return redirect('/')->with('error','Invalid username or password');
}
在这里,我首先要检查登录凭据是否正确,如果它们无效则直接显示错误消息“无效的用户名或密码”,如果假设登录凭据正确,那么我正在尝试登录,如果用户处于非活动状态,那么我想显示“您需要验证您的帐户”的消息,如果用户处于活动状态,那么它会将用户重定向到仪表板。
但在我的情况下,即使我 bcrypt 密码并与 db 表中的密码进行交叉检查,我也无法验证用户身份。
【问题讨论】:
-
这不是我想要的,我的查询使用 bcrypt 我无法交叉验证存储在表中的密码,还有其他方法吗?
-
您将
$request->input('password')传递给credentials,这不是使用bcrypt散列的密码。 -
你好,请检查第 3 行和第 4 行,我想要一个解决方案
-
好的。您在数据库中存储
Active和Inactive的位置.. 给我字段名称..
标签: php laravel authentication laravel-5