(不使用数据库)设计一个密码记录及查询小软件,模拟记录自己在各个网站上所使用的账号及密码,保存在文件中。要求自行设计存储方式,并实现浏览,查询,增加,删除,修改等基本操作,可自行拓展其他功能。
拓展功能:
①对软件进行加密,并使用用户指定的秘钥对文件中存储的密码进行加密,如果密码输错,则密码解密出来的是乱码,无法看到正确的密码。本程序利用简单的二进制凯撒密码将字符串通过gbk编码后进行转化。
②wxpython GUI编程。
③提供两种查找方式一种是下来列表查找,另外一种是输入查找。
代码:
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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
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来编辑。
⑤密码修改:
修改后: