import re
def click(event):
username = username_entry.get()
password = password_entry.get()
print(f"Clicked, User = {username}")
expression = r'(.*).....$' # Match any characters before the last 5 characters
masked_password = re.sub(expression, r'\1*****', password) # Substitute last 5 characters with '*'
print(f"Masked Password = {masked_password}")
if password.lower() == str('password'):
print("Password: GOOD")
print(f"'{password.lower()}' = 'password'?")
if any(char.isdigit() for char in password):
print("Int: GOOD")
if len(password) >= 8:
print("Length: GOOD")
else:
print("Length: BAD")
else:
print("Int: BAD")
else:
print("Please fill out all the required fields")
Result:
Clicked, User = Username
Masked Password = Pas*****
Password: GOOD
'password' = 'password'?
Int: BAD
The password seems to be "password", so why isnt it detecting that?
I have no idea why this isnt working, it should say "Please fill out all the required fields"
>Solution :
Two issues:
1)
Change
if password.lower() == str('password'):
to
if password.lower() != str('password'):
This is you main problem, the code goes in the wrong direction due to this
- Invert the condition or the code inside the statement where you check for any digit:
The any() function returns True if any element of an iterable is True. If not, it returns False. As none of the char is digit in password, you will go to the else statement
Should work like this:
if any(char.isdigit() for char in password):
print("Int: BAD")
else:
print("Int: GOOD")
if len(password) >= 8:
print("Length: GOOD")
else:
print("Length: BAD")