Aquí, intento validar una contraseña y verificar si hay mayúsculas y números en la contraseña antes de guardarla como una variable diferente. Usando funciones, ¿es posible que lo haga? Las sangrías han cambiado en el formato, así que por favor ayúdenme con otros aspectos.


def length(long):
    while len(long) < 10:
        print("Please make your password longer, up to at least 10 characters.")
        print("Your password is only " + str(len(long) + " characters long")

if password.isupper() = True:
  print("Welcome to this student interface")
  username = input("Please enter a username")
  password = input("Please enter a strong password")
  length(password)

Esto es lo que he hecho ahora:

def length(long):
    bool LengthCheck = False
    if len(long) < 10:
        print("Please make your password longer, up to at least 10 characters.")
        print("Your password is only " + str(len(long) + " characters long")
    else:
        LengthCheck = True

errors = []

print("Welcome to this student interface")
username = input("Please enter a username")
password = input("Please enter a strong password")
length(password)

bool Capcheck = False
bool DigCheck  = False

while CapCheck = False or CapCheck = False:
    length(password)

    if not any(x.isupper() for x in password):
        errors.append("Your password needs at least 1 capital.")
    else:
        CapCheck = True
        break

    if not any(x.islower() for x in password):
        errors.append("......... Why?")

    if not any(x.isdigit() for x in password):
        errors.append("You need to have at least 1 digit")
    else:
        DigCheck = True
        break

    if errors:
        print(" ".join(errors))
        password = input("Please enter a stronger password")

Aparentemente hay un error con mi booleano aquí, por favor ayuda

def length(long):
    bool LengthCheck = False
    if len(long) < 10:
        print("Please make your password longer, up to at least 10 characters.")
        print("Your password is only " + str(len(long) + " characters long")
    else:
        LengthCheck = True
1
newdevclueless 10 abr. 2020 a las 16:50

2 respuestas

La mejor respuesta

Intenta usar islower():

password.islower()

Esto devuelve True si no hay mayúsculas en la contraseña.


Ahora, si desea verificar si tiene el número i, debe seguir a @jubnvz:

any(i.isdigit() for i in password)

O una forma más específica:

any(map(str.isdigit, password))

Y para sus entradas de contraseña, intente:

while True:
    password = input(""Please enter a strong password:")
    if not any(x.isupper() for x in password):
        print("Your password needs at least 1 upper case.")
    elif not any(x.isdigit() for x in password):
        print("You need to have at least 1 digit")
    elif not any(x.islower() for x in password):
        print("Your password needs at least 1 lower case.")
    elif len(password) < 10:
        print("Please make your password longer, up to at least 10 characters.")
        print("Your password is only " + str(len(password)) + " characters long")
    else:
        break

Si lo desea y también confirma una contraseña, intente:

while True:
    password = input(""Please enter a strong password:")
    if not any(x.isupper() for x in password):
        print("Your password needs at least 1 upper case.")
    elif not any(x.isdigit() for x in password):
        print("You need to have at least 1 digit")
    elif not any(x.islower() for x in password):
        print("Your password needs at least 1 lower case.")
    elif len(password) < 10:
        print("Please make your password longer, up to at least 10 characters.")
        print("Your password is only " + str(len(password)) + " characters long")
    else:
        passwordcon = input(""Please confirm your password:")
        if passwordcon == password:
            break
        else:
            print("Your passwords do not match, try again'")
4
InfinityTM 10 abr. 2020 a las 18:30
 any([p.isupper() for p in password])    
1
jubnzv 10 abr. 2020 a las 13:54