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

salting is good #6

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
14 changes: 11 additions & 3 deletions auth.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import json
import string
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 @@ -22,13 +24,19 @@ def pwhash(password):
return pwh

def add_user(pwdb, username, password):
salty=salt()
if username not in pwdb:
pwdb[username] = password
pwdb[username] = ("".join(salty),pwhash("".join(salty)+password))
def salt():
chars=list(string.ascii_lowercase)
random.shuffle(chars)
return chars[0:5]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could join here, so you can get a nice string from this function to avoid having to do it outside



def authenticate(username, password, pwdb):
if username in pwdb:
if password == pwdb[username]:

if pwhash("".join(pwdb[username][0])+password) == pwdb[username][1]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it correct/necessary to use join here for the extracted salt?

return True
else:
return False
Expand Down