在此代码段中使用time.sleep()
函数的确切目的是什么:
def check_user(user: User, password: str) -> bool:
hashpass, salt = user_info[user].hashed_password
target_hash_pass = hash_password(password, salt)[0]
sleep(random.expovariate(10))
return secrets.compare_digest(hashpass, target_hash_pass)
[尝试在验证密码时引入随机的时间延迟,可能是为了对付timing attacks。