-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify.py
131 lines (111 loc) · 4.86 KB
/
verify.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#python projects
#password generator and validator gui using flet
import flet as ft
import pyperclip
import random
import re
from flet import TextField, Checkbox, ElevatedButton, Text, Row, Column
from flet_core.control_event import ControlEvent
def main(page: ft.Page) -> None:
page.title = "password creator/validator"
page.vertical_alignment = ft.MainAxisAlignment.START
page.theme_mode = ft.ThemeMode.DARK
page.window_width = 500
page.window_height = 500
page.window_resizable = False
password_generator: TextField = TextField(label="digit(8-100)", text_align=ft.TextAlign.LEFT, width=200)
checkbox_copy: Checkbox = Checkbox(label="copy to clipboard", value=False)
button_generate: ElevatedButton = ElevatedButton(text="generate", width=200, disabled=True)
password_validator = TextField(label="password", text_align=ft.TextAlign.LEFT, width=200)
button_validate = ElevatedButton(text="validate", width=200, disabled=True)
password_length = password_generator.value
data = {
'digits':range(10),'string':['a', 'b',"KD","JEI","NDN3", "WS","HEI", '77;', '!js', 'kk',"F", "G", "H",
"J", "K", "J", "G", "K", "O", "G", "F", "H", "K", "J", "Y", "F", "N", "R", "E", "W", "A", "S" 'knsuj',
'c', 'd', '+)#j', 'skER', 'knur', 'ioe', 'f', 'hjkskkksjo', 'g', 'h', 'i', 'j', 'hejikdnhjd', 'k', 'l',
'm', 'n', 'o', 'p', 'qbsnoku+$();', 'r', 's', 't', 'uvw', 'x', 'y', 'z'] ,
'symbols': ['@', '!', '^', '_', '=' '#', '$', '%', '&']
}
def generate(param: ControlEvent) -> None:
global password_length, selected_cases
selected_cases = []
password_length = int(password_generator.value) # type: ignore
num_cases = password_length
# Select random cases
for _ in range(num_cases):
key = random.choice(list(data.keys()))
values = random.choice(data[key])
selected_cases.append((key, values))
for key, values in selected_cases:
print(f"{values}", end="")
button_generate.disabled = not checkbox_copy.value
page.update()
def submit_generate(param: ControlEvent) -> None:
page.add(
Row(
controls=[
Text(value=f"password: {''.join(str(values) for key, values in selected_cases)}", size=20, disabled=False)
],
alignment=ft.MainAxisAlignment.CENTER
)
)
def clipboard():
text_to_copy = "".join(str(values) for key, values in selected_cases)
if checkbox_copy.value:
pyperclip.copy(text_to_copy)
clipboard()
checkbox_copy.on_change = generate
password_generator.on_change = generate
button_generate.on_click = submit_generate
page.add(
Row(
controls=[
Column(
[password_generator,
checkbox_copy,
button_generate])
],
alignment=ft.MainAxisAlignment.CENTER
)
)
def validate(param: ControlEvent) -> None:
button_validate.disabled = not password_validator.value
page.update()
def validate_password(password_validator) -> str:
if len(password_validator.value) <= 7:
return "Password must be more than 7 characters"
elif len(password_validator.value) >= 50:
return "Password length may be too long!!"
elif not re.search(r"[A-Z]", password_validator.value):
return "Password must consist of uppercase"
elif not re.search(r"[a-z]", password_validator.value):
return "Password must consist of lowercase"
elif not re.search(r"[0-9]", password_validator.value):
return "Password must consist of numbers"
elif not re.search(r"[#,@,\$,\.,/?,&,%,*,^,!,_]", password_validator.value):
return "Password must consist of special characters"
else:
return "Password is strong✅"
def submit_validate(param: ControlEvent) -> None:
validation_message = validate_password(password_validator)
page.add(
Row(
controls=[
Text(value=validation_message, size=20, disabled=False)
],
alignment=ft.MainAxisAlignment.CENTER
)
)
password_validator.on_change = validate
button_validate.on_click = submit_validate
page.add(
Row(
controls=[
Column(
[password_validator, button_validate])
],
alignment=ft.MainAxisAlignment.CENTER
)
)
if __name__ == "__main__":
ft.app(target=main)