0
I need help on a question about Python strings. The statement says the following:
Write a program to read a password and check if it contains the security requirements: At least one uppercase character and one lowercase character, as well as containing numbers and letters, as well as at least 6 and at most 10 characters.
In the code I made, everything was right, until the moment I had to check if there were numbers in the password. The code is this:
while True:
senha = input('Digite sua senha: ')
list(senha)
if len(senha) < 6:
print('Deve conter no mínimo 6 caracteres.')
elif len(senha) > 10:
print('Deve conter no máximo 10 caracteres.')
else:
if any(x.isupper() for x in senha):
print('Deve conter pelo menos uma letra minúscula.')
elif any(x.islower() for x in senha):
print('Deve conter pelo menos uma letra maiúscula.')
elif any(x.isdigit() == False for x in senha):
print('Deve conter pelo menos um número.')
else:
break
print('Senha válida.')
No output tried several possible situations, to test all security requirements, but then gave problem in the last requirement that is in the code. The result in the output gave this:
Digite sua senha: ash
Deve conter no mínimo 6 caracteres.
Digite sua senha: Charlie12345
Deve conter no máximo 10 caracteres.
Digite sua senha: r4gn4rok
Deve conter pelo menos uma letra maiúscula.
Digite sua senha: H41LM4RY
Deve conter pelo menos uma letra minúscula.
Digite sua senha: Brazuka
Deve conter pelo menos uma letra minúscula.
NOTE: In the last line should have given a warning that the password must contain at least one number, but instead this message appears.
How do I solve this? Could you help me with this code?
I believe the ideal approach would be to use Regex, for each condition a regex and see if it passes the test
– Sergio Carvalho
https://answall.com/q/443332/112052
– hkotsubo