How to store the username in database under GDPR?

Viewed 1608

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:

  1. username_encrypted (encryption key will be outside the database and database will not have access to it)
  2. salt
  3. 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:

  1. Compute the hash using the user salt (the salt is different for each user) (hash(username+salt))
  2. 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):

  1. Have a global salt for all users and the column username_hash is computed with the global salt
  2. Compute the hash (hash(username+global_salt))
  3. Compare the result of previous line with column username_hash
1 Answers

You can handle it a lot like a password. A login name when hashed with a site-wide salt can be checked by much like a password; you just need to verify it, you don't need to query it.

This is not the best practice for password storage per say since you will often find a lot of people using the same passwords, but for usernames, a site-wide salt should not expose any extra vulnerability since they should all be unique.

If you need to display the username after logging in. To do this, you could save the username a person types into a logon form as a session variable before you hash it. This way the Session remembers you are JohnSmith101 for as long as you are logged in, but the database only ever knows your hash.

Related