Site icon TechVidvan

Generate Strong Random Password using Python

python project random password generator

The best way to learn a language is to practically use it. TechVidvan is back with another beginners project where we will create a Password Generator using Python. So let’s get started with the project.

About Password Generator

Nowadays security is the most important thing while working on a system. To keep a system secure on user-level one should use highly protective passwords. By protective passwords, it means that one should not use any predictive things like your date of birth, name, surname, etc.

Then the question arises what should we use? We should use a random password generating application so that no one could guess and misuse the password we have set. Now let us create a password generating application using python.

Python Password Generator Project Details

While creating the Password Generator, we will be using the Tkinter Module to create an easy GUI window and adding necessary fields to it. For generating the password we will be using the random module so that a random password is generated by choosing words from a string that we will specify. We are generating a password randomly so that it is secure to use.

Prerequisites for Password Generator using Python

To proceed with the project, you need the following :

Download Python Password Generator Project

Please download the source code of python password generator project: Python Password Generator Project Code

Steps to Create a Password Generator using Python

1. Importing Required Libraries:

#importing required libraries for TechVidvan Password Generator project using Python
from msilib.schema import CheckBox
import random
from tkinter import *
import string
import tkinter

2. Creating GUI Window:

#creating a window
window = Tk()
window.title('TechVidvan')#window title
window.geometry('500x500')#window geometry

Label(window,font=('bold',10),text='PASSWORD GENERATOR').pack()#giving label to window

3. Creating Password_Generator() Function:

#function to generate password
def password_generate(leng):
valid_char='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@_'#characters of the password
     password=''.join(random.sample(valid_char,leng))#random generation of password
     l =Label(window, text = password, font=('bold', 20)) #displaying password
     l.place(x=190,y=50)

4. Creating CheckBoxes:

Checkbutton(text='4 character',onvalue=4, offvalue=0,variable=len1).place(x=200,y=150)#creating checkbox
Checkbutton(text='6 character',onvalue=6, offvalue=0,variable=len2).place(x=200,y=170)#creating checkbox
Checkbutton(text='8 character',onvalue=8, offvalue=0,variable=len3).place(x=200,y=190)#creating checkbox
#converting string input to integer
len1=tkinter.IntVar()
len2=tkinter.IntVar()
len3=tkinter.IntVar()

5. Function to get the length of Password:

#function to check the checkbox
def get_len():
  if len1.get() == 4:
     password_generate(4)
  elif len2.get() == 6:
     password_generate(6)
  elif len3.get() == 8:
     password_generate(8)
  else:
     password_generate(6)

6. Creating Button and Main Command to Run:

Button(window,text='Generate',font=('normal',10), bg='yellow',command=get_len).place(x=200,y=100)
window.mainloop()#run the window

Finally we execute the mainloop() method that runs our window and displays what we have created.
Hurray! We have successfully created a Password Generator using Python. Now let us have a look at how our GUI window will look.

Python Password Generator Output

This is how a password will be generated based on the user choice of it’s length.

Summary

We successfully completed the creation of a Password Generator using Python. During the creation of this project, we learned the following-

Exit mobile version