-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy path1-Random Password.py
More file actions
52 lines (39 loc) · 1.29 KB
/
1-Random Password.py
File metadata and controls
52 lines (39 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import random
import string
from tkinter import *
def password_generator():
result = ""
for i in range(1, 11):
result = result + random.choices(
string.ascii_uppercase + string.digits + string.punctuation + string.ascii_lowercase).pop()
return result
def is_suitable_password(password):
upper_case_count = 0
lower_case_count = 0
digit_count = 0
symbol_count = 0
for i in password:
if string.ascii_lowercase.count(i) > 0:
lower_case_count += 1
elif string.ascii_uppercase.count(i) > 0:
upper_case_count += 1
elif string.punctuation.count(i) > 0:
symbol_count += 1
else:
digit_count += 1
if digit_count >= 2 and upper_case_count >= 2 and symbol_count >= 2:
return True
else:
return False
def press():
while True:
new_password = password_generator()
if is_suitable_password(new_password) is True:
l1.config(text=new_password)
break
main_frame = Tk(className=" Password Generator App")
main_frame.geometry("400x400")
b1 = Button(main_frame, text="Generate password", command=press).pack()
l1 = Label(main_frame, text="Welcome")
l1.pack()
main_frame.mainloop()