Back

User login only if account status is active.


mikkas70 posted 2 years ago

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.

slillo replied 2 years ago 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.

mikkas70 replied 2 years ago

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.

Angelin replied 1 year ago

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 ?

ettiennelouw replied 11 months ago

Would also like to know where to change this?

zarpio replied 8 months ago

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.

zarpio replied 8 months ago

Finally I found the answer from a champion :-)

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

phpspider replied 4 months ago

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


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us