Reputation: 21
I'm in a project where I need to create a random secret unique hash for every user every 24h. The problem is that the table of Users has around 5M rows and I think that a cronjob that updates all the rows in the table is a bit much. My database is a Postgres. Is there a PostgreSQL field that permits this kind of behaviour in an optimal way? Thanks in advance
Upvotes: 2
Views: 60
Reputation: 538
Interesting. What you could do here is to generate a salted hash including your current date instead of storing to the database a hash that you have to refresh every 24 hours.
For example, in Python3 you could use hashlib.md5(b"<seed>:<user_id>:<today_date>")
and every day at 00.00 a new unique hash for User X will be re-created.
Upvotes: 2