Keep track of your user's salt+hash combinations in another table and compute their new hash using old salts to make sure they've never tried to use it before.
An example...
Let's say your user's password history is in a list of dicts:
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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…