python - GetPassWarning:无法控制终端上的回显
问题描述
我正在创建一个骰子游戏,并想引入密码哈希,用户需要输入他们的用户名和密码。我是散列新手,我试过这个:
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.
所以我尝试了一个不同的ide(从idle到intellij pycharm)但同样的问题仍然出现。
我看到了其他问题,但
an environment where stdin, stdout and stderr are connected to /dev/tty, or another PTY-compliant device.
对我来说真的没有意义我试图发表评论,但我需要更多代表。我也在 PyCharm 上运行而不是空闲
解决方案
回显输入是因为 while 循环从未退出,因为条件不满足:字典中的密码存储为纯文本,只需要散列字典中的值。
def check_password(hashed_password, user_password):
password, salt = hashed_password.split(':')
return password == hashlib.sha256(salt.encode() + user_password.encode()).hexdigest()
推荐阅读
- angular - WebStorm 不会在 Angular CLI 应用程序中遇到断点
- google-apps-script - 如何在 Google 电子表格中创建自定义的时间驱动触发器
- reactjs - 在 github repo 上使用 NPM 安装 React 依赖项
- symfony - 带有 redis 的 Symfony 应用程序在 Gitlab CI 中失败
- r - 使用 Shiny 写入和保存到 excel 文件
- ios - 如何将特定颜色转换为 HSV/RGB 标量值(通道 4)?
- postgresql - 将数据从 postgres 数据库移动到具有不同所有者的另一个数据库
- bash - 如何检查 .sql 脚本执行是否成功?
- java - 模拟 DateFormat、SimpleDateFormat、Date 类
- flutter - 将值从 android 传递到颤振,但不是从主要活动