The problem is that I have certain requirements that need to be met as a verification for the password. So when I enter the requirements correctly, there is no problem and the program continues. However, when one of the requirements is not met it enters the while loop like it's supposed to, but then won't break out of it once the requirements are met. Can someone help me understand what is wrong?
By the way, I'm importing re module.
def input_password(self):
print('Password must be 8-12 characters, must contain at least one uppercase and lowercase letter,'
'and one number.')
self.__input_password = input('Password: ')
flag = 0
while True:
if len(self.__input_password) < 8:
flag = -1
break
elif len(self.__input_password) > 12:
flag = -1
break
elif not re.search("[a-z]", self.__input_password):
flag = -1
break
elif not re.search("[A-Z]", self.__input_password):
flag = -1
break
elif re.search("\s", self.__input_password):
flag = -1
break
else:
flag = 0
print('Valid Password')
break
while flag == -1:
print('Invalid Password. Please reenter.')
print('Password must be 8-12 characters, must contain at least one uppercase and lowercase letter,'
' and one number.')
self.__input_password = input('Password: ')
When a valid password is entered, it outputs:

When an invalid password is entered, it outputs:

I appreciate all help given.
breakstatements.while Trueon the first iteration no matter what the conditions are. Why not just remove it?