Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import getpass, hashlib
- class Login_System:
- # Test database containing user:passwordhash
- database = {'user1':'72b302bf297a228a75730123efef7c4', #Password = banana
- 'admin':'21232f297a57a5a743894a0e4a801fc3'} #Password = admin
- def __init__(self):
- '''
- Simple constructor
- '''
- self.logged = False
- def main_loop(self):
- '''
- Simple login loop
- '''
- while not self.logged:
- h = hashlib.md5()
- user = raw_input('Username: ')
- psw = h.update(getpass.getpass('Password:'))
- psw = h.hexdigest()
- if user in self.database:
- if self.database[user] == psw:
- self.logged = True
- return True
- else:
- rep = raw_input('Wrong password, quit? [Y/N]').lower()
- if rep == 'y':
- return False
- else:
- rep = raw_input('Unsername not found, quit? [Y/N]').lower()
- if rep == 'y':
- return False
- l_sys = Login_System()
- rep = l_sys.main_loop()
- if rep:
- print('Succesfully logged!')
- raw_input('Press enter to exit.')
Advertisement
Add Comment
Please, Sign In to add comment