Python密码存储器

您所在的位置:网站首页 python本地存储 Python密码存储器

Python密码存储器

2024-02-04 18:25| 来源: 网络整理| 查看: 265

(不使用数据库)设计一个密码记录及查询小软件,模拟记录自己在各个网站上所使用的账号及密码,保存在文件中。要求自行设计存储方式,并实现浏览,查询,增加,删除,修改等基本操作,可自行拓展其他功能。

拓展功能:

①对软件进行加密,并使用用户指定的秘钥对文件中存储的密码进行加密,如果密码输错,则密码解密出来的是乱码,无法看到正确的密码。本程序利用简单的二进制凯撒密码将字符串通过gbk编码后进行转化。

②wxpython GUI编程。

③提供两种查找方式一种是下来列表查找,另外一种是输入查找。 更多内容访问omegaxyz.com

代码:

import wx password = {} num = [] class InfoPanel(wx.Frame): def __init__(self, parent, id): global password wx.Frame.__init__(self, parent, id, "密码管家", pos=(0, 0), size=(480, 300)) panel = wx.Panel(self, -1) self.proof = None self.userpw(self) self.load_file(self) rev = wx.StaticText(panel, -1, '欢迎使用密码小管家!', pos=(50, 0)) rev.SetForegroundColour("black") rev.SetBackgroundColour("") rev2 = wx.StaticText(panel, -1, '记录总数', pos=(200, 0)) self.total_pw = wx.TextCtrl(panel, -1, "", pos=(250, 0), size=(20, 20)) rev3 = wx.StaticText(panel, -1, '所有记录', pos=(5, 30)) self.PSList = wx.Choice(panel, -1, choices=list(password), pos=(60, 30), size=(100, -1)) button2 = wx.Button(panel, wx.ID_ANY, pos=(161, 29), size=(80, 27), label='显示') button2.Bind(wx.EVT_BUTTON, self.show_password) self.findpw = wx.TextCtrl(panel, -1, "", pos=(250, 30), size=(100, -1)) button5 = wx.Button(panel, wx.ID_ANY, pos=(351, 29), size=(100, 27), label='查找') button5.Bind(wx.EVT_BUTTON, self.find_password) rev4 = wx.StaticText(panel, -1, '密码', pos=(15, 65)) self.PSList_show = wx.TextCtrl(panel, -1, "", pos=(60, 60), size=(180, 35)) rev5 = wx.StaticText(panel, -1, '强度', pos=(250, 65)) self.strength = wx.TextCtrl(panel, -1, "", pos=(280, 60), size=(30, -1)) button3 = wx.Button(panel, wx.ID_ANY, pos=(0, 100), size=(220, 30), label='修改') button3.Bind(wx.EVT_BUTTON, self.revise_password) button4 = wx.Button(panel, wx.ID_ANY, pos=(220, 100), size=(220, 30), label='删除') button4.Bind(wx.EVT_BUTTON, self.del_password) rev_ = wx.StaticText(panel, -1, '-----------------------------------------------------------------------------------------', pos=(0, 150)) rev6 = wx.StaticText(panel, -1, '名称', pos=(15, 180)) rev6 = wx.StaticText(panel, -1, '密码', pos=(180, 180)) self.temp_Name = wx.TextCtrl(panel, -1, "", pos=(60, 180), size=(100, -1)) self.temp_key = wx.TextCtrl(panel, -1, "", pos=(225, 180), size=(100, -1)) button = wx.Button(panel, wx.ID_ANY, pos=(330, 180), size=(100, 26), label='添加记录') button.Bind(wx.EVT_BUTTON, self.get_password) self.get_total_pw(self) def userpw(self, event): dlg = wx.TextEntryDialog(None, "请输入用户口令:", '秘钥认证') while True: try: if dlg.ShowModal() == wx.ID_OK: self.proof = int(dlg.GetValue()) except: pass dlg2 = wx.MessageDialog(self, '将使用您的口令加密与解码,若口令错误你将无法看到正确密码', '注意!!!', wx.OK | wx.ICON_INFORMATION) dlg2.ShowModal() dlg2.Destroy() break dlg.Destroy() def load_file(self, event): global password global num f = open("E:\\密码记录.txt", 'r') for line in f.readlines(): if ':' in line and line[:line.index(':')] not in num: password[line[:line.index(':')]] = line[line.index(':')+1:len(line)-1] num.append(line[:line.index(':')]) f.close() def add_password(self, name, key): f = open("E:\\密码记录.txt", 'a+') if name != "" and key != "": f.write(name + ':' + key + '\n') f.close() self.PSList.Append(name) self.get_total_pw(self) def get_password(self, event): global num if self.temp_Name.GetValue() != None and self.temp_key.GetValue() != None: if self.temp_Name.GetValue() in num: dlg = wx.MessageDialog(self, '记录已经存在', '!', wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() dlg.Destroy() else: raw = self.temp_key.GetValue() raw = encrypt(self.proof, raw) self.add_password(self.temp_Name.GetValue(), raw) self.load_file(self) self.PSList.Refresh() self.temp_Name.Clear() self.temp_key.Clear() def get_total_pw(self, event): global num self.total_pw.Clear() self.total_pw.AppendText(str(len(num))) def show_password(self, event): temp = self.PSList.GetSelection() self.PSList_show.Clear() self.PSList_show.AppendText(decrypt(self.proof, password[num[temp]])) self.strength.Clear() if self.judge(decrypt(self.proof, password[num[temp]])): self.strength.AppendText('强') else: self.strength.AppendText('弱') def revise_password(self, event): global num global password temp = self.PSList.GetSelection() temp2 = None dlg = wx.TextEntryDialog(None, "请输入修改后的密码:", '修改密码') while True: try: if dlg.ShowModal() == wx.ID_OK: temp2 = dlg.GetValue() break except: pass dlg.Destroy() if temp2 != "": f = open("E:\\密码记录.txt", 'r+') new_key = num[temp] + ':' + encrypt(self.proof, temp2) + '\n' x = f.readlines() flag = x.index(num[temp] + ':' + password[num[temp]] + '\n') x[flag] = new_key password[num[temp]] = encrypt(self.proof, temp2) f = open("E:\\密码记录.txt", 'w+') f.writelines(x) f.close() self.strength.Clear() if self.judge(decrypt(self.proof, temp2)): self.strength.AppendText('强!') else: self.strength.AppendText('弱!') def del_password(self, event): global num global password temp = self.PSList.GetSelection() f = open("E:\\密码记录.txt", 'r+') x = f.readlines() flag = x.index(num[temp] + ':' + password[num[temp]] + '\n') del password[num[temp]] del num[temp] x[flag] = "" f = open("E:\\密码记录.txt", 'w+') f.writelines(x) f.close() self.PSList.Delete(temp) self.get_password(self) self.PSList_show.Clear() self.strength.Clear() self.get_total_pw(self) def find_password(self, event): global password if self.findpw.GetValue() != "": temp = self.findpw.GetValue() self.PSList_show.Clear() try: self.PSList_show.AppendText(decrypt(self.proof, password[temp])) except: self.PSList_show.AppendText("没有找到!!") def judge(self, pw): if len(pw) < 10: return False flag = [0, 0, 0, 0] symbol = ['_', '!', '@', '#', '%', '^', '*', '(', ')', '&'] for i in pw: if i.isupper(): flag[0] = 1 elif i.islower(): flag[1] = 1 elif i.isdigit(): flag[2] = 1 elif i in symbol: flag[3] = 1 else: return False if sum(flag) >= 3: return True else: return False class MainApp(wx.App): def OnInit(self): self.frame1 = InfoPanel(None, -1) self.frame1.Center() self.frame1.Show(True) self.SetTopWindow(self.frame1) return True if __name__ == '__main__': app = MainApp(0) app.MainLoop()

以上代码缺少加密与解密模块(请理解!!,谢谢支持!!)

完整代码请访问:http://download.csdn.net/download/xyisv/10208927

运行截图:

①秘钥认证; 这里写图片描述 这里写图片描述 ②主界面: 这里写图片描述 ③密码查找(包括强度判断): 这里写图片描述

验证密码在txt文件中如何保存(经过加密) 这里写图片描述 注意如果秘钥错误则显示的不是正确的密码 例如我此时输入错误的秘钥:此时密码杂乱无章!!!

④添加密码:

这里写图片描述

如果重复会显示:

这里写图片描述

注意如果要记录一个网站的多个用户则可以像CSDN1 CSDN2来编辑。 ⑤密码修改: 这里写图片描述 修改后: 这里写图片描述 更多内容访问omegaxyz.com 网站所有代码采用Apache 2.0授权 网站文章采用知识共享许可协议BY-NC-SA4.0授权 © 2018 • OmegaXYZ-版权所有 转载请注明出处



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3