Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 3. (Password Checker) Implement the function is_valid() in password_chec

ID: 3708468 • Letter: P

Question

Problem 3. (Password Checker) Implement the function is_valid() in password_checker.py that returns True if the given password string meets the following specifications, and False otherwise: • At least eight characters long. • Contains at least one digit (0-9). • Contains at least one uppercase letter. • Contains at least one lowercase letter. • Contains at least one character that is neither a letter nor a number. Hint: use the str methods isdigit(), isupper(), islower(), and isalnum(). $ python password_checker .py Abcde1fg False $ python password_checker.py Abcde1@g True File Linux Mint [Running] password_checker.py (/coursework/homework8) Edit View Search Tools Documents Help on% OO 9 import stdio import sys # Returns True if pwd is a valid password and False otherwise. def is_valid (pwd): # Test client [DO NOT EDIT]. Reads a password string as command-line argument # and writes True if it's valid and False otherwise. def main(): pwd = sys.argv[1] stdio.writeln(is_valid(pwd)) if == ' main ': name _main()

Explanation / Answer

# Python program to check validation of password

# Module of regular expression is used with search()

import re

password = "R@m@_f0rtu9e$"

flag = 0

while True:  

if (len(password)<8):

flag = -1

break

elif not re.search("[a-z]", password):

flag = -1

break

elif not re.search("[A-Z]", password):

flag = -1

break

elif not re.search("[0-9]", password):

flag = -1

break

elif not re.search("[_@$]", password):

flag = -1

break

elif re.search("s", password):

flag = -1

break

else:

flag = 0

print("Valid Password")

break

if flag ==-1:

print("Not a Valid Password")

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote