Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement salting #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions auth.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import json
import random

def get_credentials():
username = input('Enter your username: ')
password = pwhash(input(f'Enter your password {username}: '))
password = input(f'Enter your password {username}: ')

return username, password

Expand All @@ -23,12 +24,14 @@ def pwhash(password):

def add_user(pwdb, username, password):
if username not in pwdb:
pwdb[username] = password
salt = random.randint(1, 10000)
pwdb[username] = (salt, pwhash(str(salt) + password))


def authenticate(username, password, pwdb):
if username in pwdb:
if password == pwdb[username]:
usr_salt, usr_pwdhash = pwdb[username]
if pwhash(str(usr_salt)+password) == usr_pwdhash:
return True
else:
return False
Expand Down