I'm developing a hybrid app where the user has the possibility to click "remember me" when logging in with username and password. In case user has only 1 "stored" account it automatically logs him in, but in case he has more than 1 "stored" account, the app shows him the list of the available accounts (like the one when logging into Gmail).
To implement the above behaviour, I have come up with this procedure:
- At the first login the username and password are sent to server via HTTPS
- If the credentials are correct, the server generates a token with such procedure:
- merge username and password hash into a string
- hash the string again with SHA and a server secret
- substitute the chars in the string
- create a N-char string (token) from the string
- This token is then sent back to the device and the username and this token are stored to LocalStorage
- From now on the user logs in with the username and this token (automatically or when clicking the account he wants to login into)
Would this be secure enough or should I improve something? I'm a bit worried though about storing usernames into LS, but that's the only information I have when showing the user what account he's logging into.
Edit: There can be several different people (for instance family members) logged in the account, because the app controls a device.