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

时间:2019-01-26 12:23:55

标签: python hash

我正在创建一个骰子游戏,想要引入密码哈希,并且要求用户输入用户名和密码。我是哈希的新手,并且尝试了此操作:

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)

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

GetPassWarning: Can not control echo on the terminal.

所以我尝试了一个不同的想法(从空闲状态转为intellij pycharm) 但是仍然出现了同样的问题。

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

1 个答案:

答案 0 :(得分:0)

回显了输入,因为while循环从未退出,因为不满足条件: 字典中的密码存储为纯文本 只是需要对字典中的值进行哈希处理。

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