网站备案可以更改吗服务器安全

当前位置: 首页 > news >正文

网站备案可以更改吗,服务器安全,2023新冠结束了吗,电商网站开发前景用Python和Tkinter标准模块建立密码管理器 创建一个简单的密码管理器应用程序#xff0c;帮助用户存储和管理他们的密码。使用Python的tkinter模块来创建一个图形用户界面#xff08;GUI#xff09;。 本程序支持 添加、查看、搜索、复制、修改、删除 功能。 本程序使用 …用Python和Tkinter标准模块建立密码管理器 创建一个简单的密码管理器应用程序帮助用户存储和管理他们的密码。使用Python的tkinter模块来创建一个图形用户界面GUI。 本程序支持 添加、查看、搜索、复制、修改、删除 功能。 本程序使用 SQLite建立 passwords.db用以保存密码信息。 通过强制所有密码相关操作以字符串形式处理解决前导零丢失问题。 Base64是Python的标准库模块之一用于进行Base64编码和解码操作。Base64并不是一种加密算法而是一种编码方案它不适合用于保护敏感信息在此用于简化演示。如果需要保护敏感信息如密码应使用真正的加密算法如 AES。 运行效果 源码如下 import tkinter as tk from tkinter import ttk, messagebox import sqlite3 import base64# 加密函数强制输入为字符串 def encrypt(password):password_str str(password) # 强制转为字符串return base64.b64encode(password_str.encode()).decode()# 解密函数直接返回字符串 def decrypt(encrypted_password):decrypted_bytes base64.b64decode(encrypted_password.encode())return decrypted_bytes.decode() # 直接返回字符串# 初始化数据库 def init_db():conn sqlite3.connect(passwords.db)cursor conn.cursor()cursor.execute(CREATE TABLE IF NOT EXISTS passwords (id INTEGER PRIMARY KEY AUTOINCREMENT,project TEXT NOT NULL,username TEXT NOT NULL,password TEXT NOT NULL))conn.commit()conn.close()# 添加密码强制密码为字符串 def add_password():project project_entry.get()username username_entry.get()password password_entry.get()if not project or not username or not password:messagebox.showwarning(输入错误, 请填写所有字段)returnencrypted_password encrypt(str(password)) # 强制转为字符串conn sqlite3.connect(passwords.db)cursor conn.cursor()cursor.execute(INSERT INTO passwords (project, username, password) VALUES (?, ?, ?),(project, username, encrypted_password))conn.commit()conn.close()project_entry.delete(0, tk.END)username_entry.delete(0, tk.END)password_entry.delete(0, tk.END)view_passwords()# 查看密码显示时强制转为字符串 def view_passwords():for row in tree.get_children():tree.delete(row)conn sqlite3.connect(passwords.db)cursor conn.cursor()cursor.execute(SELECT id, project, username, password FROM passwords)rows cursor.fetchall()conn.close()for row in rows:id, project, username, encrypted_password rowdecrypted_password decrypt(encrypted_password)tree.insert(, tk.END, values(id, project, username, str(decrypted_password)))# 搜索密码 def search_password():search_term search_entry.get()for row in tree.get_children():tree.delete(row)conn sqlite3.connect(passwords.db)cursor conn.cursor()cursor.execute(SELECT id, project, username, password FROM passwords WHERE project LIKE ?,(f%{search_term}%,))rows cursor.fetchall()conn.close()for row in rows:id, project, username, encrypted_password rowdecrypted_password decrypt(encrypted_password)tree.insert(, tk.END, values(id, project, username, str(decrypted_password)))# 复制密码关键修复直接从数据库获取 def copy_password():selected_item tree.selection()if not selected_item:messagebox.showwarning(未选择, 请选择一条记录)return# 获取选中行的项目名和用户名item tree.item(selected_item)project item[values][1]username item[values][2]# 直接从数据库查询原始密码conn sqlite3.connect(passwords.db)cursor conn.cursor()cursor.execute(SELECT password FROM passwords WHERE project ? AND username ?, (project, username))row cursor.fetchone()conn.close()if row:encrypted_password row[0]decrypted_password decrypt(encrypted_password)root.clipboard_clear()root.clipboard_append(str(decrypted_password)) # 强制转为字符串messagebox.showinfo(复制成功, 密码已复制到剪贴板)else:messagebox.showerror(错误, 未找到密码)# 删除记录 def delete_password():selected_item tree.selection()if not selected_item:messagebox.showwarning(未选择, 请选择一条记录)returnitem tree.item(selected_item)record_id item[values][0]confirm messagebox.askyesno(确认删除, 确定要删除这条记录吗)if not confirm:returnconn sqlite3.connect(passwords.db)cursor conn.cursor()cursor.execute(DELETE FROM passwords WHERE id ?, (record_id,))conn.commit()conn.close()view_passwords()# 修改记录关键修复输入框获取值强制为字符串 def edit_password():selected_item tree.selection()if not selected_item:messagebox.showwarning(未选择, 请选择一条记录)returnitem tree.item(selected_item)record_id item[values][0]# 直接从数据库获取原始密码conn sqlite3.connect(passwords.db)cursor conn.cursor()cursor.execute(SELECT project, username, password FROM passwords WHERE id ?, (record_id,))project, username, encrypted_password cursor.fetchone()conn.close()current_password decrypt(encrypted_password)edit_window tk.Toplevel(root)edit_window.title(修改记录)edit_window.geometry(300x200)# 项目名ttk.Label(edit_window, text项目名:).grid(row0, column0, padx5, pady5)project_entry ttk.Entry(edit_window, width25)project_entry.grid(row0, column1, padx5, pady5)project_entry.insert(0, project)# 用户名ttk.Label(edit_window, text用户名:).grid(row1, column0, padx5, pady5)username_entry ttk.Entry(edit_window, width25)username_entry.grid(row1, column1, padx5, pady5)username_entry.insert(0, username)# 密码关键输入框直接使用字符串避免转换ttk.Label(edit_window, text密码:).grid(row2, column0, padx5, pady5)password_entry ttk.Entry(edit_window, width25)password_entry.grid(row2, column1, padx5, pady5)password_entry.insert(0, str(current_password)) # 强制转为字符串def save_edit():new_project project_entry.get()new_username username_entry.get()new_password password_entry.get() # 直接获取字符串if not new_project or not new_username or not new_password:messagebox.showwarning(输入错误, 请填写所有字段)returnencrypted_password encrypt(str(new_password)) # 加密前确保为字符串conn sqlite3.connect(passwords.db)cursor conn.cursor()cursor.execute(UPDATE passwords SET project ?, username ?, password ?WHERE id ?, (new_project, new_username, encrypted_password, record_id))conn.commit()conn.close()messagebox.showinfo(成功, 记录已更新)edit_window.destroy()view_passwords()save_button ttk.Button(edit_window, text保存, commandsave_edit)save_button.grid(row3, column0, columnspan2, pady10)# 初始化数据库 init_db()# 创建主窗口 root tk.Tk() root.title(密码管理器) root.geometry(800x600)# 输入区域 input_frame ttk.LabelFrame(root, text添加密码) input_frame.pack(filltk.X, padx10, pady10)ttk.Label(input_frame, text项目名:).grid(row0, column0, padx5, pady5) project_entry ttk.Entry(input_frame, width30) project_entry.grid(row0, column1, padx5, pady5)ttk.Label(input_frame, text用户名:).grid(row1, column0, padx5, pady5) username_entry ttk.Entry(input_frame, width30) username_entry.grid(row1, column1, padx5, pady5)ttk.Label(input_frame, text密码:).grid(row2, column0, padx5, pady5) password_entry ttk.Entry(input_frame, width30) password_entry.grid(row2, column1, padx5, pady5)add_button ttk.Button(input_frame, text添加, commandadd_password) add_button.grid(row3, column0, columnspan2, pady10)# 搜索区域 search_frame ttk.LabelFrame(root, text搜索密码) search_frame.pack(filltk.X, padx10, pady10)ttk.Label(search_frame, text搜索项目名:).grid(row0, column0, padx5, pady5) search_entry ttk.Entry(search_frame, width30) search_entry.grid(row0, column1, padx5, pady5)search_button ttk.Button(search_frame, text搜索, commandsearch_password) search_button.grid(row0, column2, padx5, pady5)show_all_button ttk.Button(search_frame, text全部显示, commandview_passwords) show_all_button.grid(row0, column3, padx5, pady5)# 密码列表 tree_frame ttk.LabelFrame(root, text密码列表) tree_frame.pack(filltk.BOTH, expandTrue, padx10, pady10)columns (id, project, username, password) tree ttk.Treeview(tree_frame, columnscolumns, showheadings) tree.heading(project, text项目名) tree.heading(username, text用户名) tree.heading(password, text密码) tree.column(id, width0, stretchtk.NO) # 隐藏ID列 tree.column(password, width150) tree.pack(filltk.BOTH, expandTrue, padx5, pady5)# 操作按钮区域 button_frame ttk.Frame(tree_frame) button_frame.pack(pady10)copy_button ttk.Button(button_frame, text复制密码, commandcopy_password) copy_button.pack(sidetk.LEFT, padx5)edit_button ttk.Button(button_frame, text修改记录, commandedit_password) edit_button.pack(sidetk.LEFT, padx5)delete_button ttk.Button(button_frame, text删除记录, commanddelete_password) delete_button.pack(sidetk.LEFT, padx5)# 首次加载显示数据 view_passwords()# 运行主循环 root.mainloop()