Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- users = [{'user': "Bob", 'pass': "Bobbo1980"}, {'user': "Jim", 'pass': "JimmyBest"}]
- #encryption
- def encryption():
- charin = input(">")
- num = ord(charin)
- num += 3
- print(chr(num))
- encryption()
- #add a new user
- def new_user():
- decision = ''
- user = ''
- password = ''
- userlist = []
- while decision == '':
- decision = input("Do you want to add a new user?('y' or 'n')")
- if decision == 'n':
- return False
- if decision == 'y':
- print("Enter a name for the new user: ")
- user = input()
- for n in range(0, len(users)):
- if user == users[n]['user']:
- print("Username taken")
- decision = ''
- break
- else:
- password = password_change()
- users.append({'user': user, 'pass': password})
- print("User sucusfully added.")
- print(users)
- return True
- else:
- print("enter 'y' for yes and 'n' for no")
- decision = ''
- #changing password
- def password_change():
- password = ''
- passwordcorrect = False
- repeat = False
- rep = ''
- capitals = 0
- lowers = 0
- while passwordcorrect == False:
- password = input("Enter a new password: ")
- for n in password:
- if n in "PYFGCRLAOEUIDHTNSQJKXBMWVZ":
- capitals += 1
- if n in "pyfgcrlaoeuidhtnsqjkxbmwvz":
- lowers += 1
- if capitals >= 1 and lowers >= 1 and len(password) >= 8:
- passwordcorrect = True
- print ("Valid passowrd")
- while repeat == False:
- rep = input("repeat password: ")
- if rep == password:
- repeat = True
- print("Password susussfully changed")
- break
- else:
- print("Make sure your password has at least one capital, one lower-case and is at least 8 char long.")
- capitals = 0
- lowers = 0
- passwordcorrect = False
- return password
- #change and return password
- def change(string):
- password = ''
- while password != string:
- password = input("Enter your old password: ")
- if password == string:
- print("Success")
- return password_change()
- else:
- password = ''
- print("Password is incorect. Try again. ")
- #log in
- def log_in():
- user = ''
- password = ''
- chang = ''
- while user == '':
- user = input("Enter username: ")
- for n in range(0, len(users)):
- if users[n]['user'] == user:
- print("User in database! Enter password for " + user + ": ")
- while password == '':
- password = input("password: ")
- if password == users[n]['pass']:
- print("Loged in.")
- while chang != 'y' or chang != 'n':
- print("Do you want to change password?('y' or 'n')")
- chang = input()
- if chang == 'y':
- users[n]['pass'] = change(users[n]['pass'])
- print("New password of a user: " + users[n]['user'] + " is " + users[n]['pass'])
- break
- if chang == 'n':
- print("Quiting to menu...")
- main()
- else:
- print("Incorrect password")
- password = ''
- break
- else:
- print("No user with such a name")
- if new_user() == False:
- user = ''
- print("Enter an existing username")
- else:
- user = ''
- #main menu
- def main():
- choice = 0
- print("Welcome! Select action: ")
- while choice == 0:
- print(" 1. Log in")
- print(" 2. Add a user")
- print(" 3. List users")
- try:
- choice = int(input())
- if choice == 1:
- log_in()
- if choice == 2:
- new_user()
- choice = 0
- if choice == 3:
- for n in range(0,len(users)):
- print(users[n]['user'])
- choice = 0
- except ValueError:
- print("Invalid input. Try again.")
- choice = 0
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement