Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import getpass
- import hashlib
- usernamedb=[]
- passworddb=[]
- salt='dae9Eu2Ughiwu9maeNeichah1Pho6aaT'
- loginstatus=False
- def create_user():
- running=True
- while running:
- newusername=raw_input('Please enter a new username : ')
- newuserspassword=getpass.getpass('Please enter a password : ')
- newhashedpassword=hashlib.sha512()
- newuserspassword2=getpass.getpass('Please confirm the password : ')
- if newuserspassword==newuserspassword2:
- newhashedpassword.update(newuserspassword+salt)
- hashedtoaddtodb=newhashedpassword.hexdigest()
- usernamedb.append(newusername)
- passworddb.append(hashedtoaddtodb)
- print 'The new user has been created'
- makenewuser=raw_input('Would you like to create another user? (y/n) : ')
- if makenewuser=='n':
- break
- if makenewuser=='y':
- continue
- else:
- print 'Invalid input, taking you to login screen'
- break
- else:
- print 'Error, passwords do not match'
- continue
- def login():
- print 'Welcome to the system'
- running=True
- attempts=0
- remaining=3
- while running:
- username=raw_input('Please enter your username : ')
- password=getpass.getpass('Please enter your password : ')
- hashedinputpassword=hashlib.sha512()
- hashedinputpassword.update(password+salt)
- inputpassworddigest=hashedinputpassword.hexdigest()
- ID=usernamedb.index(username)
- if passworddb[ID]==inputpassworddigest:
- global loginstatus
- loginstatus=True
- print 'Welcome', username
- break
- if passworddb[ID]!=inputpassworddigest and remaining!=0:
- print 'Invalid password, please try again'
- attempts=attempts+1
- remaining=3-attempts
- print remaining, 'attempts remaining'
- continue
- if passworddb[ID]!=inputpassworddigest and remaining==0:
- 'You have failed to login too many times'
- break
- create_user()
- login()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement