-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
124 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import random | ||
from libs.json2gui import * | ||
|
||
|
||
LOW_LEVEL = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'] | ||
|
||
MEDIUM_LEVEL = ['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'] | ||
|
||
HIGH_LEVEL = ['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'] | ||
|
||
|
||
# 根据密码长度与复杂度,生成随机密码 | ||
def generate_password(length, level=LOW_LEVEL): | ||
return ''.join([random.choice(level) for i in range(0, length)]) | ||
|
||
|
||
# 窗口类 | ||
class Window(ttk.Frame): | ||
def __init__(self, ui_json, master=None): | ||
super().__init__(master) | ||
# 从json自动设置UI控件 | ||
create_ui(self, ui_json) | ||
# 从json自动绑定事件 | ||
create_all_binds(self, ui_json) | ||
set_combobox_item(self.__dict__["passLevelCombobox"], "中等", True) | ||
self.master.columnconfigure(0, weight=1) | ||
self.master.rowconfigure(0, weight=1) | ||
self.grid(row=0, column=0, sticky=(tk.N, tk.S, tk.E, tk.W)) | ||
self.columnconfigure(4, weight=1) | ||
|
||
def generate_password_button_callback(self, event=None): | ||
length = int(self.__dict__["pass_length"].get()) | ||
level = MEDIUM_LEVEL | ||
level_text = self.__dict__["pass_level"].get() | ||
|
||
if level_text == "简单": | ||
level = LOW_LEVEL | ||
elif level_text == "复杂": | ||
level = HIGH_LEVEL | ||
|
||
password = generate_password(length, level) | ||
self.__dict__["password"].set(password) | ||
|
||
|
||
if __name__ == '__main__': | ||
app = Window("RandomPasswordUI.json") | ||
# 设置窗口标题: | ||
app.master.title("随机密码生成器") | ||
app.master.minsize(600, 30) | ||
# 主消息循环: | ||
app.mainloop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"passLengthLabel": { | ||
"class": "Label", | ||
"int": {"width": 10}, | ||
"string": {"text": "密码长度: "}, | ||
"grid": {"row":0, "column":0} | ||
}, | ||
"passLengthEntry": { | ||
"class": "Entry", | ||
"var": "pass_length", | ||
"int": {"width": 10}, | ||
"grid": {"row":0, "column":1, "sticky":["W", "E"]} | ||
}, | ||
"passLevelLabel": { | ||
"class": "Label", | ||
"int": {"width": 10}, | ||
"string": {"text": "密码强度: "}, | ||
"grid": {"row":0, "column":2} | ||
}, | ||
"passLevelCombobox": { | ||
"class": "Combobox", | ||
"var": "pass_level", | ||
"int": {"width": 10}, | ||
"string": {"state": ["readonly"], "values": ["简单", "中等", "复杂"]}, | ||
"grid": {"row":0, "column":3, "sticky":["W", "E"]} | ||
}, | ||
"passwordEntry": { | ||
"class": "Entry", | ||
"var": "password", | ||
"int": {"width": 40}, | ||
"grid": {"row":0, "column":4, "sticky":["W", "E"]} | ||
}, | ||
"generatePasswordButton": { | ||
"class": "Button", | ||
"int": {"width": 5}, | ||
"string": {"text": "生成"}, | ||
"command": "generate_password_button_callback", | ||
"grid": {"row":0, "column":5, "sticky":["W", "E"]} | ||
} | ||
} |