我有一个与 Web 服务交互以检索帐户信息的客户端应用程序。如果用户输入错误的用户名/密码,则要求通知用户。我正在修改 Web 服务以向我的客户端返回一些内容,以提示用户输入有误。
如何使用 Python 正确实现未找到的 Web 服务的“用户名/密码”?
- 我是否告诉用户用户名存在但密码不正确?
- 我是否告诉用户没有这样的用户名,但密码匹配?
- 我是否显示未找到通用用户名/密码组合?
- 我是针对不同的情况使用不同的状态代码,还是提供包含错误的 JSON 负载?
到目前为止,这是我的代码:
from flask.ext.httpauth import HTTPBasicAuth
accounts = [
["user0", "password0"],
["user1", "password1"],
]
@app.route('/accountlist')
@auth.login_required
def accountlist()
username = auth.username();
if ... : #check if accounts does not have the given username
#notify the sender that there is no such username
return Response('Not Authorized', 401, {'WWW-Authenticate': 'Basic'})
else:
#proceed to check password and retrieve/return account information
最佳答案
Do I show a generic username/password combination is not found?
是的。为什么你认为这是“通用的”?因为它是标准。这是正确的方法,因为黑客无法对用户名进行网络钓鱼。
关于python - 如何使用 Flask HTTP Auth 为 Web 服务实现 "Incorrect username/password"提示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25267424/