Advertisement
Guest User

bob

a guest
Apr 10th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.88 KB | None | 0 0
  1. users = [{'user': "Bob", 'pass': "Bobbo1980"}, {'user': "Jim", 'pass': "JimmyBest"}]
  2.  
  3.  
  4.  
  5. #encryption
  6. def encryption():
  7.     charin = input(">")
  8.     num = ord(charin)
  9.     num += 3
  10.     print(chr(num))
  11.    
  12. encryption()
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20. #add a new user
  21. def new_user():
  22.     decision = ''
  23.     user = ''
  24.     password = ''
  25.     userlist = []
  26.     while decision == '':
  27.         decision = input("Do you want to add a new user?('y' or 'n')")
  28.         if decision == 'n':
  29.             return False
  30.         if decision == 'y':
  31.             print("Enter a name for the new user: ")
  32.             user = input()
  33.             for n in range(0, len(users)):
  34.                 if user == users[n]['user']:
  35.                     print("Username taken")
  36.                     decision = ''
  37.                     break
  38.                 else:
  39.                     password = password_change()
  40.                 users.append({'user': user, 'pass': password})
  41.                 print("User sucusfully added.")
  42.                 print(users)
  43.                 return True
  44.                    
  45.            
  46.            
  47.            
  48.            
  49.         else:
  50.             print("enter 'y' for yes  and 'n' for no")
  51.             decision = ''
  52.        
  53.    
  54.    
  55.  
  56. #changing password
  57. def password_change():
  58.     password = ''
  59.     passwordcorrect = False
  60.     repeat = False
  61.     rep = ''
  62.     capitals = 0
  63.     lowers = 0
  64.     while passwordcorrect == False:
  65.         password = input("Enter a new password: ")
  66.         for n in password:
  67.             if n in "PYFGCRLAOEUIDHTNSQJKXBMWVZ":
  68.                 capitals += 1
  69.             if n  in "pyfgcrlaoeuidhtnsqjkxbmwvz":
  70.                 lowers += 1
  71.         if capitals >= 1 and lowers >= 1 and len(password) >= 8:
  72.             passwordcorrect = True
  73.             print ("Valid passowrd")
  74.             while repeat == False:
  75.                 rep = input("repeat password: ")
  76.                 if rep == password:
  77.                     repeat = True
  78.                     print("Password susussfully changed")
  79.                     break
  80.            
  81.         else:
  82.             print("Make sure your password has at least one capital, one lower-case and is at least 8 char long.")
  83.             capitals = 0
  84.             lowers = 0
  85.             passwordcorrect = False
  86.     return password
  87.  
  88.  
  89. #change and return password
  90. def change(string):
  91.     password = ''
  92.     while password != string:
  93.        
  94.         password = input("Enter your old password: ")
  95.         if password == string:
  96.             print("Success")
  97.             return password_change()
  98.         else:
  99.             password = ''
  100.             print("Password is incorect. Try again. ")
  101.  
  102.  
  103. #log in                
  104. def log_in():
  105.     user = ''
  106.     password = ''
  107.     chang = ''
  108.     while user == '':
  109.         user = input("Enter username: ")
  110.         for n in range(0, len(users)):
  111.             if users[n]['user'] == user:
  112.                 print("User in database! Enter password for " + user + ": ")
  113.                 while  password == '':
  114.                     password = input("password: ")
  115.                     if password == users[n]['pass']:
  116.                         print("Loged in.")
  117.                         while chang != 'y' or chang != 'n':
  118.                             print("Do you want to change password?('y' or 'n')")
  119.                             chang = input()
  120.                             if chang == 'y':
  121.                                 users[n]['pass'] = change(users[n]['pass'])
  122.                                 print("New password of a user: " + users[n]['user'] + " is " + users[n]['pass'])
  123.                                 break
  124.                             if chang == 'n':
  125.                                 print("Quiting to menu...")
  126.                                 main()
  127.                                
  128.                                
  129.                     else:
  130.                         print("Incorrect password")
  131.                         password = ''
  132.                    
  133.                 break
  134.         else:
  135.             print("No user with such a name")
  136.             if new_user() == False:
  137.                 user = ''
  138.                 print("Enter an existing username")
  139.             else:
  140.                 user = ''
  141.  
  142. #main menu
  143. def main():
  144.     choice = 0
  145.     print("Welcome! Select action: ")
  146.    
  147.     while choice == 0:
  148.        
  149.         print("    1. Log in")
  150.         print("    2. Add a user")
  151.         print("    3. List users")
  152.         try:
  153.             choice = int(input())
  154.             if choice == 1:
  155.                 log_in()
  156.             if choice == 2:
  157.                 new_user()
  158.                 choice = 0
  159.             if choice == 3:
  160.                 for n in range(0,len(users)):
  161.                     print(users[n]['user'])
  162.                     choice = 0
  163.                
  164.  
  165.         except ValueError:
  166.             print("Invalid input. Try again.")
  167.             choice = 0
  168.    
  169.    
  170.    
  171.  
  172. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement