cartalyst / sentinel

A framework agnostic authentication & authorization system.
BSD 3-Clause "New" or "Revised" License
1.51k stars 238 forks source link

How do I get Sentinel to authenticate checking additional fields? #554

Closed adam-jones-net closed 3 years ago

adam-jones-net commented 3 years ago

I have added an additional criteria to the authenticate() call in Sentinel as I have a column in my users table called 'enabled'. That needs to be set to 1 for a user to login. My authentication request to Sentinel is as follows:

if (Sentinel::authenticate(['username'=> $request->log, 'password' => $request->pwd, 'enabled' => 1],$rememberMe)){

however even for users where the record is set to 0, the authentication still passes. It seems that this enabled field is just ignored completely.

What am I doing wrong ?

brunogaspar commented 3 years ago

Hi

You can achieve this by Extending Sentinel, more specifically, the User model.

Then on the extended User model, you need to add a protected $loginNames = ['email', 'enabled']; property, which be default only contains the email field.

Hope it helps.

adam-jones-net commented 3 years ago

Thanks so much @brunogaspar , that did the trick!