I’m learning MySQL and PHP through a book at the library. I was improving the security of the password encrypting system by changing the password storage from
password=SHA('password')
to
password=SHA(CONCAT('password', '--', registration_date))
where registration_date is the timestamp when the user registered.
The current code for registering users is:
INSERT INTO users (first_name, last_name, email, password, registration_date)
VALUES ('first_name', 'last_name', 'email', SHA(CONCAT('password', '--', NOW())), NOW());
Will I need to worry about the two different NOW() functions in there? Is there a possibility of them having slightly different times? I tried it with a couple of queries and it seemed to work ok.
If there is a problem, how would I fix it?
There’s no problem. From the manual:
As the manual shows by example, every evaluation of
NOW()within a statement returns the same value, regardless of how much time has passed between the evaluations.