1
+ import os .path
2
+ # Python program to generate random
3
+ # password using Tkinter module
4
+ import random
5
+ import pyperclip
6
+ from tkinter import *
7
+ from tkinter .ttk import *
8
+
9
+ # Function for calculation of password
10
+ def low ():
11
+ entry .delete (0 , END )
12
+
13
+ # Get the length of passowrd
14
+ length = var1 .get ()
15
+
16
+ lower = "abcdefghijklmnopqrstuvwxyz"
17
+ upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
18
+ digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 !@#$%^&*()"
19
+ password = ""
20
+
21
+ # if strength selected is low
22
+ if var .get () == 1 :
23
+ for i in range (0 , length ):
24
+ password = password + random .choice (lower )
25
+ return password
26
+
27
+ # if strength selected is medium
28
+ elif var .get () == 0 :
29
+ for i in range (0 , length ):
30
+ password = password + random .choice (upper )
31
+ return password
32
+
33
+ # if strength selected is strong
34
+ elif var .get () == 3 :
35
+ for i in range (0 , length ):
36
+ password = password + random .choice (digits )
37
+ return password
38
+ else :
39
+ print ("Please choose an option" )
40
+
41
+
42
+ # Function for generation of password
43
+ def generate ():
44
+ password1 = low ()
45
+ entry .insert (10 , password1 )
46
+
47
+
48
+ # Function for copying password to clipboard
49
+ def copy1 ():
50
+ random_password = entry .get ()
51
+ pyperclip .copy (random_password )
52
+
53
+
54
+
55
+ def checkExistence ():
56
+ if os .path .exists ("info.txt" ):
57
+ pass
58
+ else :
59
+ file = open ("info.txt" , 'w' )
60
+ file .close ()
61
+
62
+ def appendNew ():
63
+ file = open ("info.txt" , 'a' )
64
+ userName = entry1 .get ()
65
+ website = entry2 .get ()
66
+ Random_password = entry .get ()
67
+ usrnm = "UserName: " + userName + "\n "
68
+ pwd = "Password: " + Random_password + "\n "
69
+ web = "Website: " + website + "\n "
70
+ file .write ("---------------------------------\n " )
71
+ file .write (usrnm )
72
+ file .write (pwd )
73
+ file .write (web )
74
+ file .write ("---------------------------------\n " )
75
+ file .write ("\n " )
76
+ file .close
77
+ # This function will append new password in the txt file
78
+ file = open ("info.txt" , 'a' )
79
+
80
+
81
+ def readPasswords ():
82
+ file = open ('info.txt' , 'r' )
83
+ content = file .read ()
84
+ file .close ()
85
+ print (content )
86
+
87
+ # Main Function
88
+ checkExistence ()
89
+ # create GUI window
90
+ root = Tk ()
91
+ var = IntVar ()
92
+ var1 = IntVar ()
93
+
94
+
95
+
96
+ # Title of your GUI window
97
+ root .title ("Python Password Manager" )
98
+
99
+
100
+ # create label for length of password
101
+ c_label = Label (root , text = "Length" )
102
+ c_label .grid (row = 1 )
103
+
104
+ # create Buttons Copy which will copy
105
+ # password to clipboard and Generate
106
+ # which will generate the password
107
+ copy_button = Button (root , text = "Copy" , command = copy1 )
108
+ copy_button .grid (row = 0 , column = 2 )
109
+ generate_button = Button (root , text = "Generate" , command = generate )
110
+ generate_button .grid (row = 0 , column = 3 )
111
+
112
+ # Radio Buttons for deciding the
113
+ # strength of password
114
+ # Default strength is Medium
115
+ radio_low = Radiobutton (root , text = "Low" , variable = var , value = 1 )
116
+ radio_low .grid (row = 1 , column = 2 , sticky = 'E' )
117
+ radio_middle = Radiobutton (root , text = "Medium" , variable = var , value = 0 )
118
+ radio_middle .grid (row = 1 , column = 3 , sticky = 'E' )
119
+ radio_strong = Radiobutton (root , text = "Strong" , variable = var , value = 3 )
120
+ radio_strong .grid (row = 1 , column = 4 , sticky = 'E' )
121
+ combo = Combobox (root , textvariable = var1 )
122
+
123
+ # Combo Box for length of your password
124
+ combo ['values' ] = (8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 ,
125
+ 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 , 25 ,
126
+ 26 , 27 , 28 , 29 , 30 , 31 , 32 , "Length" )
127
+ combo .current (0 )
128
+ combo .bind ('<<ComboboxSelected>>' )
129
+ combo .grid (column = 1 , row = 1 )
130
+
131
+
132
+ # create label and entry to show
133
+ # password generated
134
+ userName = Label (root , text = "Enter username here" )
135
+ userName .grid (row = 2 )
136
+ entry1 = Entry (root )
137
+ entry1 .grid (row = 2 , column = 1 )
138
+
139
+
140
+ # create label and entry to show
141
+ # password generated
142
+ website = Label (root , text = "Enter website address here" )
143
+ website .grid (row = 3 )
144
+ entry2 = Entry (root )
145
+ entry2 .grid (row = 3 , column = 1 )
146
+
147
+ Random_password = Label (root , text = "Generated password" )
148
+ Random_password .grid (row = 4 )
149
+ entry = Entry (root )
150
+ entry .grid (row = 4 , column = 1 )
151
+
152
+
153
+ save_button = Button (root , text = "Save" , command = appendNew )
154
+ save_button .grid (row = 2 , column = 2 )
155
+ show_button = Button (root , text = "Show all passwords" , command = readPasswords )
156
+ show_button .grid (row = 2 , column = 3 )
157
+
158
+ # start the GUI
159
+ root .mainloop ()
0 commit comments