Skip to content

Instantly share code, notes, and snippets.

@leotada
Last active July 7, 2021 14:45
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leotada/26d863007e13fb1856cdc047110d0ed6 to your computer and use it in GitHub Desktop.
Save leotada/26d863007e13fb1856cdc047110d0ed6 to your computer and use it in GitHub Desktop.
obfuscate Email python
def hide_email(email):
m = email.split('@')
return f'{m[0][0]}{"*"*(len(m[0])-2)}{m[0][-1]}@{m[1]}'
# Test
print(hide_email('emailsecreto@gmail.com'))
@shashankrnr32
Copy link

shashankrnr32 commented Nov 21, 2020

This is a bit buggy.

hide_email('e@gmail.com')

will return 'ee@gmail.com'

Minor Fix:

return f'{m[0][0]}{"*"*(len(m[0])-2)}{m[0][-1] if len(m[0]) > 1 else ""}@{m[1]}'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment