This is not a duplicate of How to handle emails as usernames under GDPR? because my question is related with performance.
I have an application that I want to make comply with GDPR.
My strategy for storing personal information is to encrypt it, but I am having a hard time figuring out how to handle usernames.
I have been searching for other questions, like this one, but I can't find any with the same problem I have.
My question is related to how I should store and validate the username in the database.
The approach I was thinking of is to have three columns:
- username_encrypted (encryption key will be outside the database and database will not have access to it)
- salt
- username_hash: hash(username+salt)
When I want to retrieve the username in plain text, I get the username_encrypted and I decrypt it.
When I want to validate the username, for each user in database, I must Option 1:
- Compute the hash using the user salt (the salt is different for each user) (hash(username+salt))
- Compare the result of the previous point with the username_hash column
So, my question is: Is there another way to achieve the same goal without computing the hash of all users? For a smaller database this may not be a problem. But for a bigger database this can have a big impact.
If it's relevant, the database I am using is PostgreSQL.
Validate the username Option 2 (see Nosajimiki answer/comment below):
- Have a global salt for all users and the column username_hash is computed with the global salt
- Compute the hash (hash(username+global_salt))
- Compare the result of previous line with column username_hash