Question

In: Computer Science

Python Coding 1. validate_username_password(username, password, users): This function checks if a given username and password matches...

Python Coding

1. validate_username_password(username, password, users): This function checks if a given username and password matches in the stored users dictionary. This function returns True if a match found otherwise returns False.

2. validate_existing_user(users): This function asks for username and password and checks if user provided name and password matches. It prints an informational message and returns username if it does find a match. Call validate_username_password() function to perform this validation. A user has total of three chances to validate. After trying three times the function will print another error message and returns False.

Solutions

Expert Solution

Python code

def validate_username_password(username,password,users):

if username in users.keys():

if users[username]==password:

return True

return False

def validate_existing_user(users):

userchances=3
i=0
while i<3:

usernameinput=input("Enter username: ")
passwordinput=input("Enter password: ")
if validate_username_password(usernameinput,passwordinput,users)==True:

print("User exists.")
return usernameinput

i=i+1

print("Invalid user.")
return False

usersdict={"user1":"passwdabc","user2":"passwdpqr"}

print(validate_username_password("user1","passwdabc",
usersdict))
print(validate_username_password("userx","passwdxxx",
usersdict))
print(validate_username_password("user1","passwd",
usersdict))

print(validate_existing_user(usersdict))

Sample output 1// check validate conditions

True                                                               

False                                                              

False                                                              

Enter username: user2                                              

Enter password: passwdpqr                                          

User exists.                                                       

user2   

Sample output 2 //check no of validations

True                                                               

False                                                              

False                                                              

Enter username: adfds                                              

Enter password: sdffdsf                                            

Enter username: jfsdf                                              

Enter password: sfddsf                                             

Enter username: user1                                              

Enter password: passwdabc                                          

User exists.                                                       

user1  

Sample output 3 //display error is invalid

True                                                               

False                                                              

False                                                              

Enter username: fsdfsd                                             

Enter password: sfds                                               

Enter username: dfdfs                                              

Enter password: sdf                                                

Enter username: sdfs                                               

Enter password: sfds                                               

Invalid user.                                                      

False


Related Solutions

In PYTHON: Write a program that asks for a password from a user and checks if...
In PYTHON: Write a program that asks for a password from a user and checks if it satisfies the conditions: Contains at least one lowercase letter (a-z). Contains at least one uppercase letter (A-Z). Contains at least one digit (0-9). Minimum length 6 characters. Contains no spaces. If the password is valid, then the program prints “password accepted”. Otherwise, it keeps asking for more passwords from the user until a valid password is obtained. Hint: You might like to check...
I'm making a python program that checks the users input. If the users input does not...
I'm making a python program that checks the users input. If the users input does not match the rules then the program will output "No". If the users input does match the rules it will output "Yes". The rules are : at least 5 uppercase letters at least 5 lowercase letters at least 5 numbers No more than 20 characters in total I have managed to meet these conditions in individual python files but not in one. Ideally without importing...
I'm making a python program that checks the users input. If the users input does not...
I'm making a python program that checks the users input. If the users input does not match the rules then the program will output "No". If the users input does match the rules it will output "Yes". The rules are : 5 uppercase letters 5 lowercase letters 5 numbers First letter must be capitilized The total characters must be 15 I have managed to meet these conditions in individual python files but not in one. Ideally without importing anything, still...
Use python write a function that checks the result of the blackjack game, given the sum...
Use python write a function that checks the result of the blackjack game, given the sum of all cards in player 1’s and player 2’s hand in each round. For the i-th round, the i-th index of player1 list represents the sum of all cards of player1, and the i-th index of player2 list represents player2's card sum. The i-th index of the returned list should be the winner's card sum. If both players' card sums go over 21 in...
PLEASE ANSWER WASNT ANSWERED PYTHON You will ask 3 questions USERNAME = "user1" PASSWORD = "password1"...
PLEASE ANSWER WASNT ANSWERED PYTHON You will ask 3 questions USERNAME = "user1" PASSWORD = "password1" What is your user name? What is your password? What is your age? If the user name and password are incorrect, display a message that says - Your credentials are not valid If both user name and password are correct, ask question 3 If the answer to question 3 is eighteen and greater, display a message that says - You're considered an adult If...
How would you call a username in a different function when coding in C? I have...
How would you call a username in a different function when coding in C? I have a function that logs a user in, and I would like to say if (username == 'abc'){do function} but everytime I use the 'username' variable in a different function, it says it is an undeclared identifier.
Q-1) a client wants to log into a server by using username and password first name...
Q-1) a client wants to log into a server by using username and password first name a suitable http mechanism like cookie or session to make it happen and then make a signal flow diagram to show that how does it happen
Part#1 What are the default username and password for Kali Linux? How many bits is the...
Part#1 What are the default username and password for Kali Linux? How many bits is the MD5 hashing algorithm? How many bits is the SHA1 hashing algorithm? Which hashing algorithm is more accurate, MD5 or SHA1? Part#2 What is the command to unmount a partition? In what directories are mount points typically created on Linux? When the ls –l command is used, what is designated in the first column to indicate a file? When the ls –l command is used,...
Write a function called checkFormat that will check the format of a given username to make...
Write a function called checkFormat that will check the format of a given username to make sure it follows some formatting restrictions. This function should take one input parameter – a string that contains the username to be checked. The username should look like [email protected] where cccc can be any 4 lowercase letters. The following conditions must be satisfied to be a valid username: The length should be 19 characters The 5th character should be “@” The username should end...
Python please Write a function that takes a string as an argument checks whether it is...
Python please Write a function that takes a string as an argument checks whether it is a palindrome. A palindrome is a word that is the same spelt forwards or backwards. Use similar naming style e.g. name_pal. E.g. If we call the function as abc_pal(‘jason’) we should get FALSE and if we call it a abc_pal(‘pop’) we should get TRUE. Hint: define your function as abc_pal(str). This indicates that string will be passed. Next create two empty lists L1=[] and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT