chask's avatar
Level 1

How implement 'remember me' in laravel 5.4?

can you show me the step how to do ? thanks in advance.

0 likes
11 replies
chask's avatar
Level 1

i have already read it but i have no idea how to use viaRemember method in LoginCotroller

chask's avatar
Level 1

$this->validate($request, [

        'email' => 'required|email',

        'password' => 'required',

    ]);



    $remember_me = $request->has('remember') ? true : false;



    if (auth()->attempt(['email' => $request->input('email'), 'password' => $request->input('password')], $remember_me))

    {

        $user = auth()->user();

        Auth::login($user,true);

    }else{

        return back()->with('error','your username and password are wrong.');

    }

this is how i write in logincontroller

Helmchen's avatar
$user = auth()->user();
Auth::login($user,true); 

you don't need that

The rest looks good to me

chask's avatar
Level 1

i removed it what you said but it doesn't work after i logout in login form email and password doesn't show

Snapey's avatar
Snapey
Best Answer
Level 122

Remember me passes a cookie to the user so that if they return to the site they are automatically validated

If the user Logs out then they will have to login again as the remember token at the server end is discarded (for safety)

The way to test is to login, then close the browser. Reopen the browser and visit some of the restricted content. You will be automatically logged in.

So to re-iterate. If you logout then you must login. The remember function DOES NOT populate the password field. This is something you browser does if you have it enabled.

1 like
chask's avatar
Level 1

thanks for your information .

rajeshtva's avatar

@snapey does it depend on the session expiry that we set on laravel_session cookie. because in my application, i have set session_expiry time to 1 minute (just for testing). and when this duration ends then i am automatically logged out even though i have set my remember_me cookie expiry time to 1 year. also on trying to access restricted page (home page) it sends me to login page.

Snapey's avatar

Hi @rajesh-kumar

I did some work on this a few years back, testing ways to handle expired session. You can see the repository here;

https://github.com/snapey/uxp

You can try it out at the link provided on the repository. If you create an account then logout, then login selecting 'remember me' then go to the form page, wait for the session timeout (3 minutes). You will then see a page with a clock. Click the link on the page and you will be directly back to the form without logging in.

Please or to participate in this conversation.