laravellaravel-4.2

How to get log in when having multiple email


Having same email id but password different

abc@xyz.com => 123456
abc@xyz.com =>  987654

I want to get logged in after match email and password

if (Auth::attempt($credentials, true)) {
    //Check first email and password if it does match return true else false
}

How could this possible to achieve, please guide and elobrate if possible thanks a ton in advance


Solution

  • You could start by retrieving all Users with the given email.

    $users = User::where('email', $request->get('email'))->get();
    
    $users->each(function (User $user) {
        if (\Hash::check($request->get('password'), $user->password)) {
            Auth::login($user);
        }
    });
    

    You then iterate over all the users and check the password yourself.