In: Computer Science
Password Checking
Software to reset passwords often requires the user to enter the
password twice, checking to make sure it was entered the same way
both times. Write a program in Python that contains
functions/methods in it that can verify that the two passwords
entered are correct. Your project should contain a method that asks
the user to enter a password twice, then either tell the user that
the two entries were not the same and then start the process over
again. Or, if they are the same, tell the user that the new
password was accepted.
Additionally, the user is required to enter a password that meets specific security requirements. Proper Passwords are required to follow these rules:
Your task is to create a project to verify whether or not a prospective proper password meets these requirements and that the user has entered the correct password in twice. Hint, a modular solution to this assignment will be the most efficient approach to meeting the requirements of this project
The project should identify to the user the types of rule violations that are contained in an improperly entered password
The project should use a modular solution using user-defined functions
import re
def main():
#prompts user to enter password
pwd1 = input("Enter password: ")
#prompts user to reenter password
pwd2 = input("Enter password again: ")
#declare the string of special characters
special_characters = "!@$%^&*()-_=+[];:'\",<.>/?"
#initialize valid to 1
valid = 1
#checks if pwd1 is equal to pwd2 or not
if(pwd1 == pwd2):
#if pwd1 = pwd2 then cheks for validation of password
while True:
#cheks if password have min length 12 or not
#if min length <12 then set valid = 0
if (len(pwd1)< 12):
print("Password must have minimum length 12")
valid = 0
break
#cheks if password contain atleast 1 lower case character or not
#if password not contain atleast 1 lower case then set valid = 0
elif not re.search("[a-z]",pwd1):
print("Password must contain atleast 1 lower case character")
valid = 0
break
#cheks if password contain atleast 1 upper case character or not
#if password not contain atleast 1 upper case then set valid = 0
elif not re.search("[A-Z]",pwd1):
print("Password must contain atleast 1 upper case character")
valid = 0
break
#cheks if password contain atleast 1 digit or not
#if password not contain atleast 1 digit then set valid = 0
elif not re.search("[0-9]",pwd1):
print("Password must contain atleast 1 digit")
valid = 0
break
#cheks if password contain atleast 1 special character or not
#if password not contain atleast 1 special character then set valid = 0
elif not any(c in special_characters for c in pwd1):
print("Password must contain atleast 1 special charater")
valid = 0
break
#cheks if password contain space or not
#if password contain space then set valid = 0
elif(re.search(r"\s", pwd1)):
print("Password must not contain space")
valid = 0
break
#cheks if password start with alpha numeric character or not
#if password not start with alpha numeric character then set valid = 0
elif(not pwd1[0].isalnum()):
print("Password must start with alpha numeric character")
valid = 0
break
#cheks if password contain repeating character or not
#if password contain repeating character then set valid = 0
elif valid == 1:
for i in range(len(pwd1) -1):
if(pwd1[i] == pwd1[i+1]):
print("Password must not contain repeating character")
valid = 0
break
if(valid == 0):
break
#if valid = 1 that means all validation are passed
#then prints New password is accepted
if valid == 1:
print("New password is accepted")
break
#if pwd1 and pwd2 are not same
else:
print("Two entries are not the same")
valid = 0
#if valid = 0 then call main() function
if valid == 0:
main()
main()
OUTPUT: