The way I’m thinking about doing the login part of this in my projects is:
-
before login the user requests a
login_token
from the server. These are generated and stored on the server on request, and probably have a limited lifetime. -
to login the application calculates the hash of the users password, then hashes the password with the
login_token
to get a value, they then return both thelogin_token
and the combined hash. -
The server checks the
login_token
is one that it has generated, removing it from its list of validlogin_token
s. The server then combines its stored hash of the user’s password with thelogin_token
and ensures that it matches the submitted combined token. If it matches you have authenticated your user.
Advantages of this are that you never store the user’s password on the server, the password is never passed in the clear, the password hash is only passed in the clear on account creation (though there may be ways around this), and it should be safe from replay attacks as the login_token
is removed from the DB on use.