import osimport timeimport randomimport sysimport stringimport hashlibusers = {}class User: def __init__(self, username, password): self.username = username self.password = passwordrunning = Truewhile running: os.system("cls") print("Welcome. Please register yourself.") print() uname = input("Username: ") pword = input("Password: ") users.update({"" + uname : "" + pword}) hash_object = hashlib.sha1(pword.encode()) pswrd = open("hash.txt", "a") pswrd.write(str(hash_object)) pswrd.close() for key, value in users.items(): print() print(key, " : ", value) time.sleep(3)當(dāng)我打開文本文件時(shí),它有這個(gè):<sha1 HASH object @ 0x010E6600>我怎樣才能防止這種情況?任何幫助是極大的贊賞!PS我知道將用戶名和密碼存儲在字典中效率不高,但這是我現(xiàn)在唯一可以做到的方法。
1 回答

喵喵時(shí)光機(jī)
TA貢獻(xiàn)1846條經(jīng)驗(yàn) 獲得超7個(gè)贊
您可能想要存儲的不是哈希本身,而是它的 HEX 摘要:
hash_object.hexdigest() # 'dc7e6b79b489fa810e11889710023e7e2e36fb64'
添加回答
舉報(bào)
0/150
提交
取消