Hello
I'm looking for a way to mask emails in the database, but in a way that I can revert to them without much difficulty if I need the actual email.
My idea is to create a AFTER INSERT
trigger for this. Will not be used in production environment.
My idea was to make emails like:
[email protected]
[email protected]
[email protected]
Turn around:
[email protected]
[email protected]
[email protected]
That is, I would like to change the characters after the last period (.) of the email to a random varchar. The size of the replaced text does not have to be the same as the original text.
Does anyone know a quiet way to do this? I do not know how to take the position of the last point, this seems to be crucial to do what I want. I would not like to create a function
for this.
I can even mess up the email before @
with:
UPDATE pessoa
SET email=STUFF(email, 1, CHARINDEX('@', email)-1, LEFT(REPLACE(CAST(NEWID() AS VARCHAR(36)), '-', ''), 4+ABS(CHECKSUM(NEWID()))%4))
Resulting in:
[email protected]
But it's not what I want right now.