"Remember Me" feature at Login using local storage

Hi!

I need to add a remember me feature to the app I’m developing, I’ve added a check-box inside the login form and used jquery to store the email and password when the remember-me check box is ticked, it works well on a normal html project but not in my ionic app (I built the apk and tested too).

My jquery code :

$(function() { if (localStorage.chkbx && localStorage.chkbx != '') { $('#remember_me').attr('checked', 'checked'); $('#email').val(localStorage.email); $('#pass').val(localStorage.pass); } else { $('#remember_me').removeAttr('checked'); $('#email').val(''); $('#pass').val(''); } $('#remember_me').click(function() { if ($('#remember_me').is(':checked')) { // save username and password localStorage.email = $('#email').val(); localStorage.pass = $('#pass').val(); localStorage.chkbx = $('#remember_me').val(); } else { localStorage.email = ''; localStorage.pass = ''; localStorage.chkbx = ''; } }); }); 

I’m using an ionic starter from the market as the user/login :

How can I get this feature to work?

I’m new to ionic and Angular, I’m trying to learn while developing, so please bear with me :smiley:

P.S. Security isn’t an issue since the app is very simple and does not contain any sensitive data, therefore encrypting data stored in local storage is not needed, I just need a simple way to implement the remember me feature so that users doesn’t require to login everytime they open the app.

Thanks in advance!

Using JQ in this case isnt good approach coz u have angular, as well as u methods to work with localStorage. For reading and writing in LS u shoud use methods getItem and setItem, something like that: localStorage.setItem("someText", "Ionic is awesome"); var a = localStorage.getItem("someText"); console.log(a)

1 Like

I know you said security isn’t an issue with the app, but people are still storing their usernames and passwords so some care should be taken. It would be better for you to store a session token in local storage that will be used to authenticate, rather than storing their username and password.

2 Likes

Hi My advice is not to store any sensitive data in localstorage because is easy acessible .

You can add an extra layer of security using the keychain features storing password and username there and just use your localstorage to check if the user had the remember checkbox active or not.

Another advice just because i love it … user Localforage for angular that makes easi all this features for localstorage.

and just do something like

.run($localForage)[{
$localForage.getItem(“remember”).then(function(){
// pull your keychain pass and auto login

})

}

1 Like

Thanks for the feedback guys!
Will update when I implement it! :slight_smile: