Reputation: 1548
I am making a system which requires a temp_pass field in mysql.
The password should only be there for an hour and then get removed.
I have a few options I can think of. I suppose I could check if the password is there on log in and remove it then.
I could of course force them to change their password, and then I could remove it then.
My real question is this. Is there some way in mysql to make a field change to null after 1 hour or a limited time?
I would prefer any answers in mysqli if such a thing exits
Upvotes: 0
Views: 83
Reputation: 3411
The real solution is to have 2 columns, a temp_pass
and a temp_pass_expire
When you make a temp pass, you would do something like this:
UPDATE user
SET temp_pass = 'hashed-temp-pass',
temp_pass_expire = NOW() + INTERVAL 1 HOUR;
You can check the expiration on the MySQL side or the PHP side, whichever you're more comfortable with.
If you're comfortable enough on the MySQL side, however, I would recommend doing it on the MySQL side.
Upvotes: 2