Password Generator APP using Python
PASSWORD GENERATOR APPLICATION
Google and other applications give us suggestions when you create your new passwords Right! In the same way, python makes it too easy for you to create your password generator rather than using other tools like Google. Through this article, you will learn how python programming can be used to develop an application that enables us to generate a random password and copy to clipboard option.
· Tkinter: Tkinter is a standard python library. Python with the Tkinter module is the fastest and easiest way to develop an object-oriented GUI application. It provides us a variety of common GUI(graphical user interface) elements that we can use to build our user interface like buttons, menus, and various kinds of entry fields and display areas. This module is already discussed in previous articles. So, I would suggest reading those articles first.
· Pyperclip: This module is used to copying and pasting the content on the clipboard in python. It takes data of any type and converts it into a “string” type. It can send and receive text using functions. It works with both pythons (2.x & 3.x). It has two types of functions:1. copy() 2. paste(). Here, we are using this to copy the extracted content from the label to the clipboard.
· Random: It is a built-in module file in python that is used to generate random numbers. This module provides access to functions that support many operations.
Syntax of installation:
pip install random
Syntax of importation:
Code Explanation: Through this code, we are trying to develop a GUI application using “Tkinter” that will generate a random password for this we are using the “random” module. And to copy the random password to the clipboard “pyperclip” module is used. So, let's discuss the code.
Code: So, let’s see the code for generating the password.
# importing the tkinter module from tkinter import * # importing the pyperclip module to use it to copy our generated # password to clipboard import pyperclip # random module will be used in generating the random password import random # initializing the tkinter root = Tk() root.title("Password Generator App") root['background']='#856ff8' # setting the width and height of the gui root.geometry("450x450") # x is small case here # declaring a variable of string type and this variable will be # used to store the password generated passstr = StringVar() # declaring a variable of integer type which will be used to # store the length of the password entered by the user passlen = IntVar() # setting the length of the password to zero initially passlen.set(0) # function to generate the password def generate(): # storing the keys in a list which will be used to generate # the password pass1 = ['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', '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', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', ' ', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')'] # declaring the empty string password = "" # loop to generate the random password of the length entered # by the user for x in range(passlen.get()): password = password + random.choice(pass1) # setting the password to the entry widget passstr.set(password) # function to copy the password to the clipboard def copytoclipboard(): random_password = passstr.get() pyperclip.copy(random_password) # Creating a text label widget Label(root, text="Password Generator Application", font="Lucida 20 bold").pack() # Creating a text label widget Label(root, text="Enter the password length", font="Lucida 20 bold").pack(pady=3) # Creating a entry widget to take password length entered by the # user Entry(root, textvariable=passlen).pack(pady=3) # button to call the generate function Button(root, text="Generate Password",bg = "blue", command=generate).pack(pady=7) # entry widget to show the generated password Entry(root, textvariable=passstr).pack(pady=3) # button to call the copytoclipboard function Button(root, text="Copy to clipboard",bg = "blue", command=copytoclipboard).pack() # mainloop() is an infinite loop used to run the application when # it's in ready state root.mainloop() #OUTPUT: ''' Copied password: dg$&y$E8ze '''
1. GUI Application:
2. GENERATED Password:
Hope you like this article, keep learning and stay tuned for more amazing articles like this.