How to make the user login for an offline web app?

html, jquery, local-storage, web-applications, web-sql

Solution

If I understand the question correctly, this is how you could do it:

When logging in (online):

- Authenticate against the server, if it's correct, store the username and a hashed password (for example using Crypto JS) in the WebSql database.

- If the account already exist in the local database, generate a new hash anyway in case the user has changed his password since last login.

When logging in (offline):

- Authenticate against the local database.

This will, of course, require users to log in using the online version at least once before logging in locally. This is how for example Windows 8 does it when somebody tries to log in to their Microsoft account while disconnected.

Problem

I am building an offline web app targeting iPhone and other mobile devices. Is there any way we can keep the user authentication saved using WebSql local storage? So when you open the web app while it's offline, I want Either user to be logged in already or the user should be able to log in.

Original source