Forum

User login only if account status is active.

I'm currently developing my own app and I got stuck at the login part, it does work fine, however I'd like to check if the user account status is active or not (There's an 'active' field in my database).

Is it possible to make this verification using the laravel login system? It would be just adding another parameter to the query: "WHERE active = 1". Also, I'm using Laravel 5.

Thank you.

mikkas70
mikkas70
  • 1 year ago
slillo
Solution

If you're following this guide: http://laravel.com/docs/5.1/authentication

You shouldn't make any query manually:

if (Auth::attempt(['email' => $email, 'password' => $password, 'active' => 1])) {
    // The user is active, not suspended, and exists.
}

You can pass to attempt an array with all keys you want. The password value will be automatically hashed, you can add all fields you need to that array.

slillo said:

If you're following this guide: http://laravel.com/docs/5.1/authentication

You shouldn't make any query manually:

if (Auth::attempt(['email' => $email, 'password' => $password, 'active' => 1])) { // The user is active, not suspended, and exists. }

You can pass to attempt an array with all keys you want. The password value will be automatically hashed, you can add all fields you need to that array.

Worked perfectly, thank you so much sir.

Where exactly is that line? I can't seem to find it in my installation. I am using Laravel 5.2

Or should I create a new Controller, with only that function and then modify my routes to point to that controller ?

Would also like to know where to change this?

Anyone please help me out, I am also stuck to validate users while getting logged-in. I want to validate users having column 'active'. Users should not be get logged-in if they have 0 in active column means inactive state.

Thanks.

Finally I found the answer from a champion :-)

http://stackoverflow.com/a/31016210/202351

But what if i want to check i.e. status not equals to Deleted or Inactive ?