pythonfor-loopwhile-loop

Python Password Cracker


My code is

from random import *
guess = ""
password = input("Password: ")
letters = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
while (guess != password):
    for letter in password:
        guessletter = letters[randint(0, 25)]
        guess = str(guessletter) + str(guess)
    print(guess)
print("Password guessed!")
input("")

My goal is to get it to randomly generate letters and stick them together to make the length of the password, and do this until it finds the password. Every time I run it, it just makes the command prompt look like something from the Matrix. Is there something I'm doing wrong?

P.S. I'm doing this to see how hard it would be to crack a password. I have no intent of hacking into other people's accounts.


Solution

  • As it was already said, you are not properly resetting your guess.

    Also, that's not how you crack passwords, since you are repeating the same guesses over and over. You need to somehow go over all the possibilities, without repeating yourself.

    Say your password is 4 letters long, you can start with aaaa, then aaab, until zzzz. You may do it in another order, a random one, but you should test each case only once.