Published on

Python Script to make Password Generator

  • avatar
    Spandan Sehgal


Passwords are most important thing in our online security and the passwords must be strong so that our info can't get leaked.

So in this post, which is my first one I am going to tell you how to make a password generator in python .

Required Modules

For this python project we will require only two built-in python modules that are :-

  • string
  • random

Use of the modules

  1. string : We will use this module to add different characters to our password so it becomes strong and difficult to crack.

  2. random : We will be using this module to pick random characters .

Let's Code

Start by importing the modules

import random
import string

Now we are going to create our variables which will use string module to store all characters

str1 = string.ascii_lowercase #This will store all the lower case alphabets

str2 = string.ascii_uppercase This will store all the upper case alphabets

str3 = string.digits This will store all the digits

str4 = string.punctuation This will store all the punctuation marks which will
make our password more strong

Now we will ask user for how much length the password should be and make an empty list which will join our variables in which all characters are stored

pwdlen = int(input("Enter password length\n"))
s = []

Now finally we will generate the password and print it

print("Your password is: ")
print("".join(random.sample(s, pwdlen)))
a = input("")

You can access this code at my GitHub Repo I hope you all liked this post .

Thanks For Reading :D