# How to create Remember Me

**URL:** <https://discourse.cakephp.org/t/how-to-create-remember-me/11861>\
**Category:** Uncategorized\
**Created:** [February 10, 2024, 3:12pm UTC](https://discourse.cakephp.org/t/how-to-create-remember-me/11861 "2024-02-10T15:12:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lish](https://avatars.discourse-cdn.com/v4/letter/l/47e85d/32.png) [@lish](https://discourse.cakephp.org/u/lish)\
**Post date:** [February 10, 2024, 3:12pm UTC](https://discourse.cakephp.org/t/how-to-create-remember-me/11861/1 "2024-02-10T15:12:48Z")

</div>

Hi… everyone  
I am working on login system so I used Authentication/Authorization plugin for handle login Authentication.

Application.php middlware for cookie

```auto
->add(new EncryptedCookieMiddleware(
                // Names of cookies to protect
                ['CookieAuth', 'secrets', 'protected'],
                Configure::read('Security.cookieKey')
            ))

```

Application.php in getAuthenticationService Method

```auto
$service->loadAuthenticator('Authentication.Cookie', [
            'fields' => $fields,
            'loginUrl' => '/accounts/login',
        ]);

```

login.php

```auto
 $result = $this->Authentication->getResult();
        // If the user is logged in send them away.
        if ($result->isValid()) {
            $Users = $this->getTableLocator()->get('Users');
            $user = $Users->get($result->getData()->userkeyid);
            $user->login_time = DateTime::now();
            $Users->save($user);

                $target = '/users';
           
            return $this->redirect($target);
        }

```

login.php file in Template

```auto
<?= $this->Form->create() ?>
        <div class="mb-3">
            <?= $this->Form->control('email', ['class' => 'form-control', 'autocomplete' => "off"]) ?>
        </div>
        <div class="mb-3">
            <?= $this->Form->control('password', ['class' => 'form-control', 'autocomplete' => "off"]) ?>
        </div>
        <div class="mb-3">
            <?= $this->Form->control(' remember_me', ['type' => 'checkbox', 'class' => 'form-check-input']); ?>
        </div>
        <div class="mb-3">
            <?= $this->Form->submit('Login', ['class' => 'form-control btn btn-primary rounded-0']) ?>
        </div>
        <?= $this->Form->end() ?>

```

here you can see… i just set remeber\_me field but it does not work if user click on remember me checkbox…

can you please explain how does i do this? any code Example for remember me?

---

<div class="post-metadata">

**Author:** ![seagrinch](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@seagrinch](https://discourse.cakephp.org/u/seagrinch)\
**Post date:** [February 12, 2024, 6:33pm UTC](https://discourse.cakephp.org/t/how-to-create-remember-me/11861/2 "2024-02-12T18:33:15Z")

</div>

Is it as simple as the extra space you have before “remember\_me” in the form?
