Sometimes a tiny feature makes a huge difference in our day-to-day tasks. They make our work simple and easy. One such feature is adding ‘Remember me – Username and Password’. This feature is so ubiquitous that we feel its absence only when it is not there.

This feature is not available by default in Magento 2. This blog provides the code to add  ‘Remember me – Username and Password’ feature in Magento 2.

Implementing the below code will let formsite remember your username and password so that you do not have to re-type them when returning to the site. We recommend only enabling this if you are not at a public computer and use a single formsite account. Cookies are required.

Tested for Magento 2.1.6

Note: Please take necessary backups before you apply this code. Try it out on a development server first.

Step 1:

Create a custom module based on the Magento 2 structure in the folder app/code

Ex: Magento 2 root directory/app/code/Dckap/Rememberme

Step 2:

Create a registration.php file in the below path to define your Magento 2 extension

Magento 2 root directory/app/code/Dckap/Rememberme/registration.php

Step 3:

Create a module.xml file in the below path to define your Magento 2 extension

Magento 2 root directory/app/code/Dckap/Rememberme/etc/module.xml

Step 4:

Create di.xml file in the below path to refer overriding class

Magento 2 root directory/app/code/Dckap/Rememberme/etc/di.xml

Now Dckap\Rememberme\Controller\Account\LoginPost will be used to override

Magento\Customer\Controller\Account\LoginPost

Step 5:

Create LoginPost.php file in the below path to define an overriding controller class

Magento 2 root directory/app/code/Dckap/Rememberme/Controller/Account

The code from line 153 and 159 is the customized extra code.

Step 6:

Create Helper file  in the following path…

Magento 2 root directory/app/code/Dckap/Rememberme/Helper/Data.php

Step 7 :

Please confirm the below changes in the customer login template file.

Ex – vendor/magento/module-customer/view/frontend/templates/form or extended login form template file.

After completing the above steps, run the below Magento 2 upgrade comment in the command prompt.

The code is available on GitHub at https://github.com/jothibasuj/Remember-Me

Hope this helps. Let me know if you have any comments or suggestions.

Be the first to Know

Subscribe to our blog to get the latest articles directly to your inbox.

READY TO DRIVE SALES?

Request a Quote Today

Request a Quote

Leave a Reply

3 Comments on "How to Add ‘Remember me – Username and Password’ feature in Magento 2?"


Guest
amin
11 months 11 days ago

you shouldn’t directly edit Magento core files, as you said in step 7, i think you need to override it in a custom theme or module !

Guest
Fayyaz Khattak
1 year 3 months ago

Thanks for sharing!

Jothibasu J
Author
1 year 3 months ago

Hi Fayyaz,

Thanks for your comments.