Answer the question
In order to leave comments, you need to log in
Why does attempt return false?
I encountered an error during authentication: when trying to pass it, the Auth::attempt method returns false, although the phone and password are correct.
I think the point is that in my table password is called as passhash.
Table - User
Registration class:
protected function create(Request $data)
{
if (User::where('phone', '=', $data['phone'])->exists()) {
return response()->json(array('status' => 'error', 'msg'=>'The phone number already exists'), 422);
} else {
$user_id = User::create([
'first_name' => $data['first_name'],
'surname' => $data['surname'],
'phone' => $data['phone'],
'passhash' => bcrypt($data['password']),
]);
return response()->json(array('status' => 'created', 'id' => $user_id['id']), 201);
}
}
public function login(Request $request)
{
$credentials = [
'phone' => $request['phone'],
'password' => $request['password'],
];
if (Auth::attempt($credentials)) {
return response()->json(array('token' => 'Вы успешно авторизировались!'), 200);
} else {
return response()->json([
'error' => 'Incorrect phone or password',
], 404);
}
}
public function getAuthPassword()
{
return $this->passhash;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question