Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When users login fields are encrypted, login fails #1

Open
roarkmccolgan opened this issue Feb 14, 2021 · 7 comments
Open

When users login fields are encrypted, login fails #1

roarkmccolgan opened this issue Feb 14, 2021 · 7 comments
Labels
documentation Improvements or additions to documentation

Comments

@roarkmccolgan
Copy link

Hi

LOVE this package, thank you!

I have a problem where i would like to encrypt my registered users.
They are no longer able to login as the built in Laravel Authentication doesn't use whereEncrypted

Please will let me know how to get around this?

Thanks!

@elgibor-solution
Copy link
Collaborator

@roarkmccolgan

For laravel 5.x to 7.x, you can create postLogin function to override the logic.

For laravel 8.x, you need to create custom login controller to override the logic.

@LaravelLover069
Copy link

LaravelLover069 commented Mar 20, 2021

Hi Elgibor,

I fully agree with Roarkmccolgan, I love your package too, just implemented it in Laravel 8.x.
However, I am also struggling with achieving user authentications with encrypted email addresses.

Please be so kind to share the code for the custom LoginController function to make this work.

Many thanks in advance!

@elgibor-solution elgibor-solution added the documentation Improvements or additions to documentation label Aug 6, 2021
@constantinosergiou
Copy link

@elgibor-solution please can you share a solution for this?

@quevlu
Copy link

quevlu commented Feb 23, 2022

@LaravelLover069 @constantinosergiou can create a custom rule to retrieve the user's data with their email and check the password with hash::check

@ignacio-dev
Copy link

Was this issue ever solved?

@jefferdo
Copy link

jefferdo commented Aug 2, 2022

$user = User::whereEncrypted('email', $credentials['email'])->first();
if (!empty($user) && Hash::check($credentials['password'], $user->password)) {
       $this->guard()->login($user, $request->has('remember'));
       return $this->sendLoginResponse($request);
}

Or

$user = User::whereEncrypted('email', $credentials['email'])->first();
if (!empty($user) && Hash::check($credentials['password'], $user->password)) {
       Auth::login($user, $request->has('remember'));
      return $this->sendLoginResponse($request);
}

Would work for encrypted emails. Also i left the original non encrypted login for legacy support for none encrypted emails
Happy coding!!!!!!!! 😎😎😎

@jefferdo
Copy link

jefferdo commented Aug 2, 2022

Was this issue ever solved?

Here you go

$user = User::whereEncrypted('email', $credentials['email'])->first();
if (!empty($user) && Hash::check($credentials['password'], $user->password)) {
       $this->guard()->login($user, $request->has('remember'));
       return $this->sendLoginResponse($request);
}

Or

$user = User::whereEncrypted('email', $credentials['email'])->first();
if (!empty($user) && Hash::check($credentials['password'], $user->password)) {
       Auth::login($user, $request->has('remember'));
      return $this->sendLoginResponse($request);
}

Would work for encrypted emails. Also i left the original non encrypted login for legacy support for none encrypted emails Happy coding!!!!!!!! 😎😎😎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

7 participants