【问题标题】:How do I validate a username/password in OnReceivedHttpAuthRequest?如何验证 OnReceivedHttpAuthRequest 中的用户名/密码?
【发布时间】:2019-02-25 17:41:19
【问题描述】:

我正在尝试存储 Windows 凭据以在 web 视图中登录到 Intranet webapp。

var login = Application.Context.GetSharedPreferences("Login", FileCreationMode.Private);
string username = login.GetString("username", null);
string password = login.GetString("password", null);

if (username != null && password != null)
    handler.Proceed(username, password);

但是当密码错误时,它会一直尝试直到帐户被锁定。如何检查 Proceed 是否失败,以便我可以重新提示用户输入新凭据。

【问题讨论】:

  • 是否进入“onReceivedSslError”?
  • @LeoZhu-MSFT 不,它没有。
  • 也许你可以做一个计数,例如当计数> = 3时,你调用handler.Cancel
  • @LeoZhu-MSFT 我考虑过。但是我什么时候将它重置为0?没有成功。

标签: android xamarin webview android-webview


【解决方案1】:

这是我的建议:

int requestCount;
public override void OnReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, string host, string realm)
     {
         requestCount++;
         if(requestCount <3)
           {
             handler.Proceed(username, password);
           }
          else
           {
             //show a Dialog(with two edittext for input username and password) which notice credentials failure and reprompt the user to enter in new credentials
             //when you click Dialog's "Ok" reset requestCount to 0 and call "handler.Proceed(newUsername, newPassword);" 
             //when you click Dialog's "Cancel" call "handler.Cancel();"
           }
    }

【讨论】:

    【解决方案2】:

    问题是保存的密码不正确。

    1. 从没有用户名/密码开始
    2. 用户输入用户名/密码后,检查。如果正确 保存它,如果没有重新开始。
    3. 稍后,当需要用户名/密码时,获取它然后检查它。
    4. 如果它工作并记录,那么我们就完成了。
    5. 如果不起作用,请清除商店并重新开始

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-26
      • 2013-12-26
      • 2016-01-24
      相关资源
      最近更新 更多