python - 如何使用 Flask HTTP Auth 为 Web 服务实现 "Incorrect username/password"提示?

标签 python web-services security authentication flask

我有一个与 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/

相关文章:

python - 当我输入用户名时,未显示 "good job"

python - Python 中的嵌套 for 循环涉及 2 个文件

.net - WebReference 即使在库程序集项目中也会创建 App.config

java - bufferedReader 和 InputStreamReader 总是抛出异常

python - ROS python 错误 "The manifest (with format version 2) must not contain the following tags: run_depend"

python - 如何在图形中间画轴?

javascript - 如何处理 javascript 中的 soap 错误

linux - 使用 openssl 从服务器获取证书

java - Spring Security - @PreAuthorize 返回 404

security - 使用 PKBDF2、AES、IV 和 salt 进行更好的实践