GetPassWarning:无法控制终端上的回显

2024-06-17 02:47:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在创建一个骰子游戏,想引入密码哈希和用户需要输入他们的用户名和密码。我不熟悉哈希,我尝试了以下方法:

from getpass import getpass
from hashlib import pbkdf2_hmac as pwhash

def login(users):
    username = input('please enter username: ')
    if username not in users:
        print("access denied")
        exit()

    password_hash = None
    while password_hash != users[username]:
        password_hash = pwhash("sha256", getpass().encode("ascii"), b"t4h20p8g24j", 100000)

    print("access granted")
    return username
login(users)

然后我在控制台上收到以下消息:

^{pr2}$

所以我尝试了一个不同的ide(从idle变成intellij pycharm) 然而,同样的问题仍然出现。在

我看到了其他问题但是 an environment where stdin, stdout and stderr are connected to /dev/tty, or another PTY-compliant device. 对我来说没什么意义我试着评论但我需要更多的代表。 我也在运行PyCharm,别闲着


Tags: 用户fromimport游戏密码accessusernamelogin
1条回答
网友
1楼 · 发布于 2024-06-17 02:47:29

输入被回显,因为while循环从未退出,因为条件不满足: 字典中的密码以明文形式存储 只需要把字典里的值散列。在

def check_password(hashed_password, user_password):
    password, salt = hashed_password.split(':')
    return password == hashlib.sha256(salt.encode() + user_password.encode()).hexdigest()

相关问题 更多 >