I'm wondering which system should generate the hash and salt for a secure webapplication.
There are 3 possibilities in my setup :
- (Javascript) client
- PHP server
- MySQL server
At this moment I've implemented it in the MySQL-server inside a trigger.
What it does is take the unhashed/uncrypted password in a field called 'PasswordHash' when a new user is created, so the original password is in the INSERT
statement.
But in the INSERT Before trigger this password is hashed (SHA1) with a random salt (UUID) that is concatenated with the hash into a variable @hashandsalt
. (I already found out it's not really a good idea to store the hash and salt into separate columns).
Then I do SET NEW.PasswordHash = @hashandsalt;
so the original password is never written to the database, but replaced with the hash+salt.
Is this a good idea?
I can see a problem with the logging of MySQL, because all logged INSERT-statements of the users-table contain the original passwords then. I don't use default MySQL logging at this moment, but I'm not really sure how MySQL stores all incoming statements internally.
What would be the best option to generate the hash and salt in your opinion?