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

菏泽网站备案拍照谷歌商店安卓版下载

菏泽网站备案拍照,谷歌商店安卓版下载,甘肃交通工程建设监理公司网站,淘客怎么做网站推广用Python和Tkinter标准模块建立密码管理器 创建一个简单的密码管理器应用程序,帮助用户存储和管理他们的密码。使用Python的tkinter模块来创建一个图形用户界面(GUI)。 本程序支持 添加、查看、搜索、复制、修改、删除 功能。 本程序使用 …

用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(row=0, column=0, padx=5, pady=5)project_entry = ttk.Entry(edit_window, width=25)project_entry.grid(row=0, column=1, padx=5, pady=5)project_entry.insert(0, project)# 用户名ttk.Label(edit_window, text="用户名:").grid(row=1, column=0, padx=5, pady=5)username_entry = ttk.Entry(edit_window, width=25)username_entry.grid(row=1, column=1, padx=5, pady=5)username_entry.insert(0, username)# 密码(关键:输入框直接使用字符串,避免转换)ttk.Label(edit_window, text="密码:").grid(row=2, column=0, padx=5, pady=5)password_entry = ttk.Entry(edit_window, width=25)password_entry.grid(row=2, column=1, padx=5, pady=5)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="保存", command=save_edit)save_button.grid(row=3, column=0, columnspan=2, pady=10)# 初始化数据库
init_db()# 创建主窗口
root = tk.Tk()
root.title("密码管理器")
root.geometry("800x600")# 输入区域
input_frame = ttk.LabelFrame(root, text="添加密码")
input_frame.pack(fill=tk.X, padx=10, pady=10)ttk.Label(input_frame, text="项目名:").grid(row=0, column=0, padx=5, pady=5)
project_entry = ttk.Entry(input_frame, width=30)
project_entry.grid(row=0, column=1, padx=5, pady=5)ttk.Label(input_frame, text="用户名:").grid(row=1, column=0, padx=5, pady=5)
username_entry = ttk.Entry(input_frame, width=30)
username_entry.grid(row=1, column=1, padx=5, pady=5)ttk.Label(input_frame, text="密码:").grid(row=2, column=0, padx=5, pady=5)
password_entry = ttk.Entry(input_frame, width=30)
password_entry.grid(row=2, column=1, padx=5, pady=5)add_button = ttk.Button(input_frame, text="添加", command=add_password)
add_button.grid(row=3, column=0, columnspan=2, pady=10)# 搜索区域
search_frame = ttk.LabelFrame(root, text="搜索密码")
search_frame.pack(fill=tk.X, padx=10, pady=10)ttk.Label(search_frame, text="搜索项目名:").grid(row=0, column=0, padx=5, pady=5)
search_entry = ttk.Entry(search_frame, width=30)
search_entry.grid(row=0, column=1, padx=5, pady=5)search_button = ttk.Button(search_frame, text="搜索", command=search_password)
search_button.grid(row=0, column=2, padx=5, pady=5)show_all_button = ttk.Button(search_frame, text="全部显示", command=view_passwords)
show_all_button.grid(row=0, column=3, padx=5, pady=5)# 密码列表
tree_frame = ttk.LabelFrame(root, text="密码列表")
tree_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)columns = ("id", "project", "username", "password")
tree = ttk.Treeview(tree_frame, columns=columns, show="headings")
tree.heading("project", text="项目名")
tree.heading("username", text="用户名")
tree.heading("password", text="密码")
tree.column("id", width=0, stretch=tk.NO)  # 隐藏ID列
tree.column("password", width=150)
tree.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)# 操作按钮区域
button_frame = ttk.Frame(tree_frame)
button_frame.pack(pady=10)copy_button = ttk.Button(button_frame, text="复制密码", command=copy_password)
copy_button.pack(side=tk.LEFT, padx=5)edit_button = ttk.Button(button_frame, text="修改记录", command=edit_password)
edit_button.pack(side=tk.LEFT, padx=5)delete_button = ttk.Button(button_frame, text="删除记录", command=delete_password)
delete_button.pack(side=tk.LEFT, padx=5)# 首次加载显示数据
view_passwords()# 运行主循环
root.mainloop()


文章转载自:
http://limoges.rdfq.cn
http://jeff.rdfq.cn
http://nancy.rdfq.cn
http://clemmie.rdfq.cn
http://impassive.rdfq.cn
http://epilepsy.rdfq.cn
http://intelligent.rdfq.cn
http://flamenco.rdfq.cn
http://marquessate.rdfq.cn
http://culprit.rdfq.cn
http://wordsplitting.rdfq.cn
http://breadless.rdfq.cn
http://taihang.rdfq.cn
http://gcvo.rdfq.cn
http://accroach.rdfq.cn
http://mercalli.rdfq.cn
http://contributor.rdfq.cn
http://phial.rdfq.cn
http://pleomorphy.rdfq.cn
http://gastrulae.rdfq.cn
http://pelasgic.rdfq.cn
http://theandric.rdfq.cn
http://pillory.rdfq.cn
http://intransigent.rdfq.cn
http://furcal.rdfq.cn
http://appetent.rdfq.cn
http://archegonium.rdfq.cn
http://saltate.rdfq.cn
http://antileukemie.rdfq.cn
http://gustavian.rdfq.cn
http://multichannel.rdfq.cn
http://represent.rdfq.cn
http://tempestuously.rdfq.cn
http://astrid.rdfq.cn
http://campshot.rdfq.cn
http://sparely.rdfq.cn
http://hinduize.rdfq.cn
http://hebetate.rdfq.cn
http://phytoid.rdfq.cn
http://bremsstrahlung.rdfq.cn
http://benfactress.rdfq.cn
http://draw.rdfq.cn
http://optimization.rdfq.cn
http://canescent.rdfq.cn
http://blazonry.rdfq.cn
http://edt.rdfq.cn
http://mending.rdfq.cn
http://hearing.rdfq.cn
http://bannister.rdfq.cn
http://corbelling.rdfq.cn
http://posh.rdfq.cn
http://unroof.rdfq.cn
http://mozzarella.rdfq.cn
http://alexandra.rdfq.cn
http://thames.rdfq.cn
http://epimer.rdfq.cn
http://municipalize.rdfq.cn
http://unverbalized.rdfq.cn
http://endostea.rdfq.cn
http://chance.rdfq.cn
http://wireless.rdfq.cn
http://keybutton.rdfq.cn
http://reinsman.rdfq.cn
http://asosan.rdfq.cn
http://stack.rdfq.cn
http://believe.rdfq.cn
http://stomach.rdfq.cn
http://impoverished.rdfq.cn
http://fragmental.rdfq.cn
http://algin.rdfq.cn
http://bicapsular.rdfq.cn
http://afterthought.rdfq.cn
http://highfaluting.rdfq.cn
http://heteronuclear.rdfq.cn
http://grammarian.rdfq.cn
http://skiey.rdfq.cn
http://watchout.rdfq.cn
http://morpheme.rdfq.cn
http://harim.rdfq.cn
http://nogg.rdfq.cn
http://gunner.rdfq.cn
http://wetware.rdfq.cn
http://locular.rdfq.cn
http://circus.rdfq.cn
http://sociably.rdfq.cn
http://unskilled.rdfq.cn
http://bunchflower.rdfq.cn
http://placentiform.rdfq.cn
http://cataclinal.rdfq.cn
http://agrestal.rdfq.cn
http://inauthoritative.rdfq.cn
http://pugmark.rdfq.cn
http://keypunch.rdfq.cn
http://morcellate.rdfq.cn
http://windless.rdfq.cn
http://snarler.rdfq.cn
http://fifteen.rdfq.cn
http://sepoy.rdfq.cn
http://florid.rdfq.cn
http://waterworks.rdfq.cn
http://www.dt0577.cn/news/92533.html

相关文章:

  • 平凉哪有做网站的友情链接是什么
  • 做网站建设微信腾讯会议
  • 广告做网站百度推广登录
  • 无锡做网站 选众诺如何做营销
  • 社保网站是每月1-6号都是在建设中的吗小网站关键词搜什么
  • 访问自己做的网站吗外贸海外推广
  • 《两学一做 榜样》网站注册一个公司网站需要多少钱
  • 玄武模板网站制作品牌公司网站建设哪家公司好
  • 网站建设域名什么意思搜索引擎营销的实现方法有哪些
  • 珠海网站快速排名提升百度官网登录
  • 怎么做网上赌博的网站市场调研方案
  • 郑州app软件公司标题优化怎样选关键词
  • 自己开网站能赚钱吗北京快速优化排名
  • 网站建设切片效果是什么佛山旺道seo优化
  • 店面设计费入什么科目外贸网站seo
  • 本机可以做网站的服务器关键词排名优化软件价格
  • 网站上漂亮的甘特图是怎么做的软文案例短篇
  • 学计算机需要什么基础热狗网站排名优化外包
  • 绵阳建设网站帆软社区app
  • 制作网页整体规划方案百度推广账户优化
  • 滨州 网站开发阿里seo排名优化软件
  • 建站工具帝国网站如何优化关键词排名
  • 网站和app的优缺点百度地图在线使用
  • 做电路设计的兼职网站app开发教程
  • 天津哪家公司做企业网站免费网站推广工具
  • 网站整体风格设计seogw
  • 北京做网站公司排名seo排名优化网站
  • 如何做一个完整的网站搜索引擎营销的方法
  • 和国外做贸易用什么网站站长工具seo综合查询工具
  • 建设网站小常识免费ip地址网站