Sentry 2 Want to using two field email or phone for LOGIN

133 Views Asked by At

I am working with SENTRY 2. In my Application i want to login by EMAIL OR phone. That means one user can login via his email address and if he want he also login with his phone number. I add a phone in my users table. when i am using email its work fine.but not working for phone.

my code:

if(strpos($data['name'],'@') !== false){

            $credentials = array(
                'email'    => $data['name'],
                'password' => $data['password'],

            );
        }
        else{

            $credentials = array(

                'phone'     => $data['name'],
                'password'  => $data['password'],
            );

        }
        try{
            $user = Sentry::authenticate($credentials,false);
        }   
        catch(Cartalyst\Sentry\Users\LoginRequiredException $e)
        {
            $msg .= 'Login field is required.'.'<br />';
        }

Me always get Cartalyst\Sentry\Users\LoginRequiredException for phone .Can any one help me to get out of this.

0

There are 0 best solutions below