Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

NUST

SCHOOL OF NATURAL SCIENCE(SNS)


ASSINGNMENT 03
SUBMITTED TO:

DR.IJAZ KHAN

SUBMITTED BY:
GROUP MEMBERS:

SYED HUBDAR ALI KAZMI 366065


ARYAN AHMED CHANDIO 372493
ZULFIQAR ALI CHACHAR 369743

Department:BS math(2021)
Project code name:Password Generator
Password Generator?
Some password generators are simply random password generators. These programs produce
complex/strong passwords with combinations of numbers, uppercase and lowercase letters, and
special characters such as braces, asterisks, slashes, etc. Other types of password generators are made
to generate more recognizable passwords rather than a completely random set of characters. There
are tools for generating pronounceable passwords, as well as custom tools that allow users to set
detailed criteria. For instance, a user could set a request for a certain number of characters, a certain
mix of letters and numbers, a certain number of special characters, or any other criteria for generating
a new password. Password generators help those who have to constantly come up with new
passwords to ensure authorized access for programs and to manage a large number of passwords for
identity and access management. Other kinds of tools include a password vault, where users manage
large numbers of passwords in a secure location

ABSTACT
This is basically a mini project for the beginners to play with python. The basic purpose of the project
is to implement all the things that we had learned in python by today. This project contains the
python built in GUI named as TKINTER. We use different built in function according to the need of
project.

DESCRIPTION OF MODULE_1(PASSWORD_GENRRATOR)
In this module we have imported
Tkinter
package and its modules
pyperclip
module
,random
module.Then initialize tkinter using
TK()
Method
A variable of string type has been declared named’
Passstr
' to store the generated password
Similarly 4 variables of integer type has been declared named
>>
'passlen_smallalpha','passlen_bigalpha' ,'passlen_digits', 'passlen_specialchacha’
 to store the length of smallalphabet characters, capital alphabet characters, digits, special
characters which the user will inputon his/her choice. The above four variables are set to zero
initially using
IntVar()
A user-defined-function to generate a password will be used named 'generate()'. We have
declaredfour list
_>>
pass1, pass2, pass3, pass4
which will be having small alphabet characters, capitalalphabet characters, digits, special
characters as elements in their respective list. A passwordstring is declared, which is initially
empty, 'mylist' list will consist of pass1, pass2, pass3, pass4as its elements.Then an infinite While-
loop is runned which will append the characters to the’
password
stringone by one & will terminate on a specific condition, condition of all big, small, digits,
specialvariables being equal to zero(0).In while loop the
mylist
' list is shuffled and then the shuffled list is copied to’
List1
‘list.so the 'list1' is a list having four lists in it(nested lists).Every first element of the nested-lists
will be checked to identify the type of elements of that list.A For-loop is iterating for four
times(from 0 to 3) with the second-indexing being fixed to zero(list1[q][0])as there are four-
nested lists. As we check the first element of the first nested-list, thecorresponding list is taken
(pass1 or pass2 or pass3 or either pass4) and character is takenrandomly using random.choice()
function ,from that list. And that character is appended to'password' string. And the
corresponding variable is decremented by 1.Similarly we proceed forward for the remaining
three 3 nested lists. Again the While-loop runs,again the 'mylist' list is shuffled and copied to
'list1' list the same procedure continues. And we proceed forward for the remaining three 3
nested lists.Finally this While-loop is terminated when condition1 is true.
(condition1=(small==0 and big==0 and digits==0 and special==0))
And the password is set to.
Passstr
Using
passstr.set()
function
Description of Module_2(Strength_Checker)-
This module is used to tell the user the strength percent of his/her input password.As the user
inputs his password in the text-field and click on’
Check
' button. A percentage will be displayed indicating the strength of the password. And with
the percentage a color box willalso be displayed, red color indicates-weak password, yellow
color indicates-medium password,green color indicates-strong password
Description of Module_3 (Check_character):
1)Import Libraries
fromtkinter import *import random
2)Initialize window
root=Tk()root.geometry('400x400’)
->>
geometry() : It is use to set the width and height of the window.3)Inside check_ch function()for i
in
range (len(string)):if(string[i].isalpha()):alphabets=alphabets+1elif(string[i].isdigit()):digits=digits+
1else:special=special+1
->>
.isalpha()
: Its is use to check character is digit or not
->>
Variable
I
start from 1st character to last character and pass each character to ifcondition.In if condition if
character is alphabet than alphabet will increment by 1 else if it is digitthan digits variable get
increment by 1 and if both condition will false than special variable getincrement by 1.This
process will get repeat until i variable reach at last character in a
string.l1=Label(root, text={" alphabets ",alphabets})l1.pack()l2=Label(root, text={"
digits ",digits})l2.pack()l3=Label(root, text={" special symbol ",special
l3.pack()
>>
Root
: It is a name given by programmer to our window.label=Label(root, text=" Enter your password
")label.pack()entry=Entry(root, textvariable="")entry.pack() button=Button(root, text="Check
Character", command= check_ch) button.pack()root.mainloop()
l3.pack()
_>>
Label()
: It is use to display the the text that users can not modify
>>>
root
It is a name given by programmer to our window.label=Label(root, text=" Enter your
password ")label.pack()entry=Entry(root,
textvariable="")entry.pack() button=Button(root, text="Check Character", command=
check_ch) button.pack()root.mainloop()
>>
Text
Which we display on the label
>>>

Entry()
: It will create input filled for user
Button()
: Use to display the button on our window
>>.
Command()
: It will work when button is click
>>
Textvariabl
It is use to retrieve the text to the entry

Procedure
First we create the new project file in any IDE (pycharm, idle, viual studio).

The we import the TKINTER a built in GUI of python and create a window using Tk().

Then we gave some resolution and background color to the new window.

Then we import some module that is required for our project.

After this, we create a label on the window with ‘password generator’ title .

Then we create three radio buttons for the selection of the security of the password.

After this, we create another label of title ‘’password length”.


Then we create a length box using spin box function which is used to select the length of the
password.

After that, we create a generator button which generates the password.

Next we create an entry field to get the generated password for copy.

After that we creates two more buttons for copying or clearing the generated password.

All of these function are displayed on the window using .grid() a built in function.

After this we create three different functions which gave the functionality to all of these predefined
structure.

Then we simply check the code that is it error free if so then run it.

Implement password of generator with GUI


GUI-based password generator application is helpful for the user to generate the random Password.
Tkinter module has been imported into the script to create the user-friendly password generator
application. Random and string modules have been imported to generate the random Password by
mixing the uppercase, lowercase, digit, and special characters. The pyperclip module is used to copy
the generated Password for creating different types of user accounts. Password_Generator() function
has defined to generate the Password and store it in the password variable. CopyPassword() function
has defined to copy the generated Password after generating the Password. A Tkinter object has

How to run password generator code by using GUI

CODE

import string
import random
importpyperclip

fromtkinter import*
importpyperclip
defgenerater():
small_alphabets=string.ascii_lowercase
capital_alphabets=string.ascii_uppercase
number=string.digits
special_charactor=string.punctuation
all=(small_alphabets+capital_alphabets+number+special_charactor)
print(all)
passord_length=int(lenghbox.get())
pasword=random.sample(all,passord_length)

ifchoice.get()==1:
passwordfield.insert(0,random.sample(small_alphabets,passord_length))

ifchoice.get() == 2:
passwordfield.insert(0, random.sample(small_alphabets, passord_length))

ifchoice.get() == 3:
passwordfield.insert(0, random.sample(small_alphabets, passord_length))
def copy():
random_pasword=passwordfield.get()
pyperclip.copy(random_pasword)
root=Tk()
root.config(bg='gray20')
choice=IntVar()
Font=('arial',13,'bold')
passwordlabel=Label(root,text='Password Generator',font=('times new
romman',20,'bold'))
passwordlabel.grid()
weakradiobutton=Radiobutton(root,text='weak',value=1,variable=choice,font=Font)
weakradiobutton.grid(pady=5)

strongradiobutton=Radiobutton(root,text='strong',value=3,variable=choice,font=Font)
strongradiobutton.grid(pady=5)

mediumradiobutton=Radiobutton(root,text='medium',value=2,variable=choice,font=Font)
mediumradiobutton.grid(pady=5)

lengthlabel=Label(root,text='Password Length',font=('times new romman',16,'bold'))


lengthlabel.grid()
lenghbox=Spinbox(root,from_=5,to_=10)
lenghbox.grid()
generatebutton=Button(root,text='generate',font=Font,command=generater)
generatebutton.grid()
passwordfield=Entry(root,width=25,bd=2,font=Font)
passwordfield.grid()
copybutton=Button(root,text='copy',font=Font,command=copy)
copybutton.grid()

root.mainloop()

OUTPUT

You might also like