Hello, what would the python code look like for this task? The password rules fo
ID: 3729090 • Letter: H
Question
Hello, what would the python code look like for this task?
The password rules for a login are as follows: . have at least eight characters. be mix of uppercase and lowercase alphabets have at least two digits Can have maximum one symbol from $, #, @ . Write a function in python that checks whether a string is a valid password Write a python program that prompts the user to enter a password and displays 'valid password' if the rules are followed or 'invalid password' otherwise.Explanation / Answer
''' To solve this problem first you should check for length using len(password) function , len functions returns the number of characters in string. if len(password) is less than 8 return invalid password else check of other conditions. ***You can use input() function to read input from user. Other conditions are checked in function. Sample Input 1: Alice@123 Sample Output: valid password Sample Input 2: Alice1@M Sample Output 2: invalid password ''' #Your python program to validate password start from below line #function to validate password def isValid(password): #Declaring variables with False value has_at_least_eight_character=False has_lower_case=False has_upper_case=False has_two_digit=0 max_one_syambol=0 #checking for lenght if(len(password)>=8): has_at_least_eight_character=True #Iterating over password for ch in password: #Checking for lower case character if(ch>='a' and ch='A' and ch='0' and ch=2 and max_one_syambol==1): return "valid password" else: return "invalid password" else: return "invalid password" #Calling isValid function password=input("Enter Password: ") print(isValid(password))Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.