Creating an API for mobile applications – Authentication and Authorization

The way I’m thinking about doing the login part of this in my projects is:

  1. 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.

  2. 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 the login_token and the combined hash.

  3. The server checks the login_token is one that it has generated, removing it from its list of valid login_tokens. The server then combines its stored hash of the user’s password with the login_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.

Leave a Comment