I'm currently trying to improve our API to be more restful, therfore avoid any state on the server. I want to accomplish this with a hmac token, appended on every request. The hmac will be made with the following data-part: host, request-method, request-uri, timestamp(to avoid replays) and in case of POST/PUT also the body of the request. Any objection against this?

I'll send the hmac along with the username or maybe a hashed representation (public key) of the user to be able to have different secret keys for each user on the server.

Now I'm planning on the secret-key exchange between client (JavaScript) and server (PHP) and got the idea of just using something the server and the client already both know without exchanging it and it should still be different for every user.

So why not use the hashed password of the user as the secret key? The server has the hash of the password saved to the database next to the user in the usertable in anyway and the client can calculate the hash based on the input of the user and store it in a client session for later usage.

What are the concerns against using the hashed userpassword as a secret key?

  • 1
    Just a question, how does the client know the salt for the password? You are salting your passwords and using a correct password hashing algorithm right? Jun 24, 2014 at 14:19
  • Haha, I don't think a salt is currently used (I know it should!), just a simple hash algorithm like md5... Yeah, here we go - that answers the question, thanks! So as soon as the password is stored safely, there is no way to reuse that as the secret anymore... Exchanging the salt makes less sense than exchanging the secret... Alright, thanks, just needed a little help in my wind up brain
    – Preexo
    Jun 24, 2014 at 14:24
  • Yea, you should use PBKDF2, bcrypt or scrypt. Using MD5 is a big no-no. Jun 24, 2014 at 14:25
  • Do you want to make that an answer? That my proposal from the question is just not possible as long as one stores passwords safely...
    – Preexo
    Jun 24, 2014 at 14:27

1 Answer 1


It's not really possible just using the user's password as you can't securely store the passwords in such a way that the client can independantly derive the same key from the password. The reason being that you are required to salt a password while storing it.

The current accepted password hashing algorithms are:

  • bcrypt
  • scrypt
  • PBKDF2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .