Skip to main content

How to Make a Password Cracker using Python

In our previous Python tutorial, we have explained to make a Quiz Game with Python. In this tutorial, we will explain how brute force attacker made to crack any password using Python.

The Brute force is a type of attack to crack passwords by submitting many paswords to guess to break it.
So here in this tutorial, we will take user input as user password and show you how attackers tried to break the password.

Implement Password Cracker with Python

First we will import random module.

from random import *

We will store alphabet letters to use them to match password.

password = ['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',]

We will take user input as user password to match and crack the password.

userPass = input("\nEnter your password:")

We will have while loop untill not matched with user password. We will also has for loop using range method to match for password letters. When match find, we will display the matched password.

guessPass = ""

while (guessPass != userPass):
    guessPass = ""
    for letter in range(len(userPass)):
        guessLetter = password[randint(0, 25)]
        guessPass = str(guessLetter) + str(guessPass) 
    print(guessPass)

print("Result marched password is: ", guessPass)

Complete Code

Here is the complete code of password cracker with Python.

from random import *

userPass = input("\nEnter your password:")

password = ['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',]

guessPass = ""

while (guessPass != userPass):
    guessPass = ""
    for letter in range(len(userPass)):
        guessLetter = password[randint(0, 25)]
        guessPass = str(guessLetter) + str(guessPass) 
    print(guessPass)

print("Result marched password is: ", guessPass)

Output:

Enter your password:az
wr
fq
..
..
..
..
..
..
..
..
xj
kh
mg
az
Result marched password is:  az