How to check password without using Auth in Laravel

Harshit Vaid
May 28 · 1 min read

Hello Guys!

I am here with another interesting blog about Laravel. Many Users uses the Auth Package to authenticate users. Auth package consists of all the basic functionality like Login, Register and Forgets Password to uses But in some situations, we need to authenticate the user's password without using auth package. So in this story, I will discuss how we can authenticate the users without the help of auth.

One more thing if you are beginners then I will tell you that the Laravel uses the hash generated passwords for the users for securities reasons. Let’s start the story :

I assumed that you have created the user's table and created the user’s model.

Create a function in the controller file like below code:

public function checkUserPassword(Request $request){
$userPwd = $request->managerpwd;
$userName = $request->manageruser;

$user = User::where('id', $userName)->first();
$passwordCheck = \Hash::check($userPwd, $user->password);
if($passwordCheck){
$output = ['success' => 1,
'msg' => 'Details matched successfully'
];
}else{
$output = [
'success' => 0,
'msg' => 'Something went wrong. Details not matched'
];
}
return $output;
}

Here we have used Hash::check method for authenticating the user

This method will return true or false in the response.

I hope the above article will help you to solve the users.

Happy Coding :)

Harshit Vaid

Written by

I am web developer with 4+ years of experience in PHP and JS technologies.