python - 在密码更改中限制相同的密码
问题描述
我正在使用 tkinter 在 python 上构建一个 gui,我已经登录、注册和更改密码屏幕,将数据托管在 mysql 上,我想设置一个选项,如果用户已经选择了密码“x”,例如,他将只能再重复一次密码,之后他将无法在更改密码屏幕上选择并重复相同的密码,有什么线索吗?
解决方案
在另一个表中跟踪用户的盐+哈希组合,并使用旧盐计算他们的新哈希,以确保他们以前从未尝试过使用它。
一个例子...
假设您的用户的密码历史记录在字典列表中:
password_history = [
{
"salt": "89!$@sg",
"hash": "asdfjhlaksjdhflkjahsdlkfjh",
},
]
def has_used_password(password_history, new_password):
hashes = set(h["hash"] for h in password_history)
count = 0
for entry in password_history:
hash_with_old_salt = hash_password(new_password, entry["salt"])
if hash_with_old_salt in hashes :
count += 1
return count
推荐阅读
- javascript - jQuery.ajax 调用 for 循环来填充 HTML 元素
- xcode - NSTableView 选择的行在使用箭头键滚动时闪烁
- javascript - 当我将鼠标悬停在 div 上时,如何让鼠标指针显示手形图标?
- c - 如何从内核模块访问实时时钟?
- .net - '无法加载文件或程序集'Core.Entities,版本 = 1.0.0.0,文化 = 中性,PublicKeyToken = null'
- javascript - 解决 javascript 图表不呈现的问题
- haskell - 在 Haskell 中使用对 foldmap 的调用的频率分布
- c# - 跳得更快?(纸马里奥风格跳跃)
- java - 如何使用 iText7 对多页 PDF 进行 OCR?
- python - `pip` 成功将`discord.py` 安装到`1.3.4`,但是`print(discord.__version__)` 显示`1.3.3`