Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
135 views
in Technique[技术] by (71.8m points)

python - Limit same password in password change

I’m building a gui on python with tkinter, i’ve made a login, register and change password screens, hosting the data on mysql, i want to make an option that if user already choose password “x” for example, he will be able to repeat the password only 1 more time, after that it will not give him an option to choose and repeat the same password on the change password screen, any clue how to do it?

question from:https://stackoverflow.com/questions/65649344/limit-same-password-in-password-change

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...