How to make a strong password generator in python

How to make password generator in python
Table of Contents

Today we will see how to make strong password generator in python. You may have heard of that you need to enter a strong password on websites, apps or anything for security reasons. Hackers are very smart they have automatic tools to crack your password.

If your password is small or weak or just a name of a person, country or your dog than your account can be easily compromised that means hacked so today we will create our own strong password generator in python.

This project is very simple and easy to do you can create this project with me and submit it as your assignments or use it for generating strong password.

If you want more projects like this than you visit our coding projects page there we have many projects uploaded with source you can easily get projects just visit coderzway projects.

Make a strong password generator in python

So now we will create our password generator in python and if you are new to python than you can follow this article but before starting if you don’t have python installed than you need to download python in your computer.

You can download python from here – Download python here.

Create a python file

After downloading python you have to create a python file to write python code you can create a new folder and create a python file with .py extension.

Then open the file in a code editor I am using vs code as my code editor you can use pycharm or atom but I like vs code because it is small, fast and there are great extensions.

You can download vs code from here – download vs code

Now open the file and copy the below code I will explain what it does below

Copy the code

				
					# Import all these modules in your file
import random
import array
import string

# sets the max length of the password 
max_length = 12
password = ''
 
digits = string.digits
lowercase_letters = string.ascii_lowercase 
uppercase_letters = string.ascii_uppercase
symbols = string.punctuation
 
# combining lists 
mixed_list = digits + uppercase_letters + lowercase_letters + symbols
 
# random generation 
rand_digit = random.choice(digits)
rand_upper_letter = random.choice(uppercase_letters)
rand_lower_letter = random.choice(lowercase_letters)
rand_symbol = random.choice(symbols)
 
temp_password = rand_digit + rand_upper_letter + rand_lower_letter + rand_symbol
 
for x in range(max_length - 4):
    temp_password = temp_password + random.choice(mixed_list)
    temp_password_list = array.array('u', temp_password)
    random.shuffle(temp_password_list)
 
for x in temp_password_list:
        password = password + x
         
print(password)
				
			

Now you need to run the python file you can do it by typing this command prompt or terminal at the file location enter python and your filename like this

				
					
python filename.py 

				
			

Output

Below image is the output of the above code as you could see it prints a random password of 12 characters this is very strong password generated in python

				
					S&!K*+iMdg<3
				
			

Explaination

You need to import all these three modules all these modules come with python so you don’t need to install anything

				
					import random
import array
import string

				
			
  • random – for generating a random digit, alphabets and symbols
  • array – for combining lists
  • string – this module will give us the digits, symbols ,all lowercase and uppercase alphabets.
				
					max_length = 12 # sets the max length of the password


				
			

you can change the length of the password you want to make it lower than 5 it will give a error.

Summary

So this was a strong password generator in python I want everyone to try to create this project and you can email me at coderzway@gmail.com.

I hope you found this project helpful please share this article with your friends and teachers and if you want more projects like this do subscribe to our newsletter for daily blog updates thank you for reading have a nice day.

Share This Post
Share on facebook
Share on twitter
Share on email
Share on whatsapp

Leave a Reply

Subscribe To Our Newsletter

Get updates and learn from the best

Latest Guides & Articles