Answer:
The program in Python is as follows:
print("Create your password which must have these.\nMust be 8 characters long.\nAt least one uppercase letter.\nAt least one number.")
pwd = input("Enter your password: ")
chkLength = 0; chkUpper = 0; chkLower = 0; chkDigit = 0
if len(pwd) == 8:
chkLength = 1
if (any(x.isupper() for x in pwd)):
chkUpper = 1
if any(y.islower() for y in pwd):
chkLower = 1
if any(z.isdigit() for z in pwd):
chkDigit = 1
if chkLength == 1 and chkUpper == 1 and chkLower == 1 and chkDigit == 1:
print("You have set the correct password.")
else:
print("Your password doesn't meet the criteria.")
if chkLength == 0:
print("It's not 8 characters long correct size.")
if chkDigit == 0:
print("Digit is missing.")
if chkLower == 0:
print("Lowercase is missing.")
if chkUpper == 0:
print("Uppercase is missing.")
Explanation:
This prints the instruction
print("Create your password which must have these.\nMust be 8 characters long.\nAt least one uppercase letter.\nAt least one number.")
This prompts the user for password
pwd = input("Enter your password: ")
This initializes check variables to 0 (0 - false)
chkLength = 0; chkUpper = 0; chkLower = 0; chkDigit = 0
If password length is 8
if len(pwd) == 8:
Set check variable of length to 1 (1 - true)
chkLength = 1
If password has uppercase
if (any(x.isupper() for x in pwd)):
Set check variable of uppercase to 1
chkUpper = 1
If password has lowercase
if any(y.islower() for y in pwd):
Set check variable of lowercase to 1
chkLower = 1
If password has digit
if any(z.isdigit() for z in pwd):
Set check variable of digits to 1
chkDigit = 1
If all check variables is 1, then the password is correct
<em>if chkLength == 1 and chkUpper == 1 and chkLower == 1 and chkDigit == 1:
</em>
<em> print("You have set the correct password.")
</em>
If otherwise,
else:
The password is incorrect
print("Your password doesn't meet the criteria.")
The following prints the corresponding criteria that is not met, depending on the value of its check variable
<em> if chkLength == 0:
</em>
<em> print("It's not 8 characters long correct size.")
</em>
<em> if chkDigit == 0:
</em>
<em> print("Digit is missing.")
</em>
<em> if chkLower == 0:
</em>
<em> print("Lowercase is missing.")
</em>
<em> if chkUpper == 0:
</em>
<em> print("Uppercase is missing.")</em>