dberube4

Login system 1

Feb 8th, 2013
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. import getpass, hashlib
  2.  
  3.  
  4. class Login_System:
  5.    
  6.     # Test database containing user:passwordhash
  7.     database = {'user1':'72b302bf297a228a75730123efef7c4', #Password = banana
  8.                 'admin':'21232f297a57a5a743894a0e4a801fc3'} #Password = admin
  9.    
  10.     def __init__(self):
  11.         '''
  12.        Simple constructor
  13.        '''
  14.        
  15.         self.logged = False
  16.  
  17.     def main_loop(self):
  18.        
  19.         '''
  20.        Simple login loop
  21.        '''
  22.        
  23.         while not self.logged:
  24.            
  25.             h = hashlib.md5()
  26.            
  27.             user = raw_input('Username: ')
  28.             psw = h.update(getpass.getpass('Password:'))
  29.            
  30.             psw = h.hexdigest()
  31.            
  32.             if user in self.database:    
  33.            
  34.                 if self.database[user] == psw:
  35.    
  36.                     self.logged = True
  37.                    
  38.                     return True
  39.                
  40.                 else:
  41.                     rep = raw_input('Wrong password, quit? [Y/N]').lower()
  42.                    
  43.                     if rep == 'y':
  44.                        
  45.                         return False
  46.  
  47.             else:
  48.                 rep = raw_input('Unsername not found, quit? [Y/N]').lower()
  49.                    
  50.                 if rep == 'y':
  51.                    
  52.                     return False
  53.                
  54.  
  55. l_sys = Login_System()
  56. rep = l_sys.main_loop()
  57.  
  58. if rep:
  59.     print('Succesfully logged!')
  60.    
  61. raw_input('Press enter to exit.')
Advertisement
Add Comment
Please, Sign In to add comment