Sumit kumar
Sumit kumar

Reputation: 402

how to work with laravel email encryption

Hi I'm trying to work with encryption of emails in user table and change auth process's "email" with encryption but not working for me keep returning my email does not match records. My RegisterController is:

User::create([
            'name' => $data['name'],
            'email' => sha1(sha1($data['email'])),
            'password' => Hash::make($data['password']),
            'referred_by' => $referred_by
        ]);

And I'm trying to do manual auth with laravel as of here: https://laravel.com/docs/6.x/authentication#authenticating-users

my LoginController:

public function authenticate(Request $request)
    {
        $credentials = $request->only(sha1(sha1('email')), 'password');

        if (Auth::attempt($credentials)) {
            // Authentication passed...
            return redirect()->intended('dashboard');
        }
    }

Note: I know sha1 is not good but i think double of sha1 for emails will be pretty hard to crack tho.

also i can't exactly find where auth is taking place (because i started learning laravel like 3 weeks ago) where i can switch user input of email field into sha1 x2 so then it can compare with users table emails.

Thanks

Upvotes: 0

Views: 1098

Answers (1)

Sumit kumar
Sumit kumar

Reputation: 402

Found the answer here: https://laracasts.com/discuss/channels/laravel/encrypt-email-field-in-users-table

Changing function login of AuthenticatesUsers by:

public function login(Request $request)
    {
        if (Auth::attempt(['email'  => sha1(sha1($request->email)), 'password' => $request->password])) {
            return redirect()->intended();
        } else {
            return $this->sendFailedLoginResponse($request);
        }
    }

thanks to saaz.

Upvotes: 1

Related Questions