[Python] Password Checker

Discussão em 'Python' iniciado por Stack, Abril 14, 2025.

  1. Stack

    Stack Membro Participativo

    I have created a password checker which generates a random character and compares it until all the characters are the same. But as it rolls through it repeats the character multiple times. Is there a way of making it so the character doesn't repeat, possibly putting the characters into a list? I could then use the

    list.del()


    function to stop it repeating. Here is my code:

    import string
    import random
    import time
    print('Welcome to the password checker')
    characters = string.ascii_lowercase + string.digits + string.ascii_uppercase + ' .,!?;:`"+/*()@#$&_-='

    password = input("Enter your password: ")
    tryFirst = ''.join(random.choice(characters) for i in range(len(password)))
    trySecond = ''

    Finished = False

    attempt = 0
    while Finished == False:
    print("{}) {}".format(attempt,tryFirst))
    trySecond = ''
    Finished = True
    for num in range(len(password)):
    if tryFirst[num] != password[num]:
    Finished = False
    trySecond += random.choice(characters)
    else:
    trySecond += password[num]
    attempt += 1
    tryFirst = trySecond
    time.sleep(0.05)
    print("Password found! That took {} attempts".format(attempt))
    if attempt < 100:
    print("Your password isn't safe")
    elif attempt < 250:
    print("Your password is quite safe, could do with improvement")
    elif attempt < 400:
    print("Your password is adequately safe")
    elif attempt < 600:
    print("Your pasword is safe")

    Continue reading...

Compartilhe esta Página