Last active
August 1, 2018 00:51
-
-
Save agnaite/233e34cab10f0aed2e98588034a630d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bcrypt | |
import six | |
def get_hashed_password(password): | |
if not isinstance(password, six.text_type): | |
password = six.text_type(password, "utf-8") | |
return bcrypt.hashpw(password, bcrypt.gensalt()) | |
def check_password(password, hashed_password): | |
if not isinstance(password, six.text_type): | |
password = six.text_type(password, "utf-8") | |
return bcrypt.checkpw(password, hashed_password) | |
def workflow(): | |
registered_users = dict() | |
num_users = 0 | |
user = {"user": "austin", "password": "banana"} | |
registered_users = register_user(user, num_users, registered_users) | |
num_users += 1 | |
is_user_registered(user, registered_users) | |
def register_user(user, i, db): | |
db[i] = {"user": user["user"], "password": get_hashed_password(user["password"])} | |
return db | |
def is_user_registered(user, db): | |
for u in db: | |
if db[u]["user"] == user["user"]: | |
return check_password(user["password"], db[u]["password"]) | |
return False | |
print(workflow()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment