import uuid import hashlib import re import random def hash_email(email): salt = uuid.uuid4().hex match = re.search(r'[\w.-]+@[\w.-]+.\w+', email) if match: print ("valid email :::", match.group()) else: print ("not valid:::") return hashlib.sha512(salt.encode() + email.encode()).hexdigest() + ':' + salt def check_email(hashed_email, user_email): email, salt = hashed_email.split(':') return email == hashlib.sha512(salt.encode() + user_email.encode()).hexdigest() new_email = input("Please enter a Email: ") hashed_email = hash_email(new_email) print('The string to store in the db is: ' + hashed_email) old_email = input("Now please enter the Email again to check: ") if check_email(hashed_email, old_email): print('You entered the right email') else: print('I am sorry but the email does not match')
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question