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

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...
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
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...
Python Question: Write a function that checks to see if an array of integers is sorted...
Python Question: Write a function that checks to see if an array of integers is sorted in an increasing fashion, returning true if it is, false otherwise. Test it with at least4 arrays - 2 sorted and 2 not sorted. Use a CSV formatted input file as described in the previous question to run your program through some tests, where again the filename is passed as an argument. Heres what I have so far: import sys # command line arguement...
Define a Python function named matches that has two parameters. Both parameters will be lists of...
Define a Python function named matches that has two parameters. Both parameters will be lists of ints. Both lists will have the same length. Your function should use the accumulator pattern to return a newly created list. For each index, check if the lists' entries at that index are equivalent. If the entries are equivalent, append the literal True to your accumulator. Otherwise, append the literal False to your accumulator. Hint: Since you must use the same index with each...
Python coding: Write code for each method listed. Input Text File Format: username|Firstname|Lastname|password|accountnumber|balance jh123|Jane|Hudson|45678910|AB45|900 ah444|Allie|Hun|ah1234|HHYZ|1500 def...
Python coding: Write code for each method listed. Input Text File Format: username|Firstname|Lastname|password|accountnumber|balance jh123|Jane|Hudson|45678910|AB45|900 ah444|Allie|Hun|ah1234|HHYZ|1500 def build_dict(): ''' Returns a dictionary created from input file where key is an existing username and value is a list of fistname, lastname, account number and balance. '''    def write_to_file(users): ''' Writes the updated user information to user list file '''
Python Coding Create function openAndReturnLastN() to meet the conditions below - accept 2 parameters; 1 string...
Python Coding Create function openAndReturnLastN() to meet the conditions below - accept 2 parameters; 1 string (name of a file) and 1 integer (N) - add a docstring - use exception handling techniques to attempt to open the filename provided, if it does not exist, return False - the file will contain an unknown number of lines - store the last N lines of the file in a single string var - return the resultant string var --- ensure to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT