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:
NOW() returns a constant time that indicates the time at which the statement began to execute. (Within a stored function or trigger, NOW() returns the time at which the function or triggering statement began to execute.)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With