Ask Question
10 October, 02:28

Some Web sites impose certain rules for passwords. Write a function that checkswhether a string is a valid password. Suppose the password rules are as follows:A password must have at least eight characters. A password must consist of only letters and digits. A password must contain at least two digits. Write a program that prompts the user to enter a password and displays validpassword if the rules are followed or invalid password otherwise.

+2
Answers (1)
  1. 10 October, 04:53
    0
    def check_password (pwd):

    c=0

    d=0

    for i in pwd:

    if (i>='a' and i='A' and i<='Z'):

    c+=1

    elif i>='0' and i<='9':

    d+=1

    c+=1

    if len (pwd) = =c and d>=2 and len (pwd) >=8:

    print ("valid password")

    else:

    print ("Invalid password")

    ps=input ("Enter password for checking : ")

    check_password (ps)

    Explanation:

    Loop through the password and check if it contains any alphabet. Increment the counter if it contains any alphabet. If it contains a number, increment both c and d variables. Finally display the relevant message.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Some Web sites impose certain rules for passwords. Write a function that checkswhether a string is a valid password. Suppose the password ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers