如何从缓存中清除Http Basic Auth用户名和密码 - android webview

时间:2017-05-17 14:54:41

标签: android android-webview

我使用android webview来显示需要基本身份验证的网页。我有代码,它接受用户名和密码,并允许成功登录到网页。但是,当用户再次访问webview时,我希望从缓存中清除用户名和密码。看起来,一旦您输入基本身份验证的用户名和密码,它就会将其保留在缓存中并自动登录。

我试过了

import time
print("Please create a new password")
password = input()
print("Re-enter your password")
password2 = input()
if password != password2:
    print("Your Passwords Do Not Match")
    time.sleep(2)
    print("Please create a new password")
    password = input()
    print("Re-enter your password")
    password2 = input()
valid = 0
lower = 0
upper = 0


for c in password:
    if c.islower():
        lower += 1
    elif c.isupper():
        upper += 1
    else:
        pass

char_count = upper + lower
if char_count >= 8:
    valid += 1
    if lower >= 1:
        valid += 1
    else:
        print("Your Password Has No Lowercase Letters")
    if upper >= 1:
        valid += 1
    else:
        print("Your Password Has No Uppercase Letters")


else:
    print("Your Password Doesn't Have 8 Characters")

if valid == 3:
    print("Your Password Is Valid. Welcome")
else:
    print("Your Password Is Invalid. Sorry")
    time.sleep(2)
    print("Please create a new password")
    password = input()
    print("Re-enter your password")
    password2 = input()

我也尝试过webview.clearFormData,webview.clearCache

但它似乎不起作用。它在没有提示输入用户名和密码的情况下自动登录。

这是我的webview片段的完整代码。

    WebViewDatabase webViewDB = WebViewDatabase.getInstance(getActivity());
    webViewDB.clearHttpAuthUsernamePassword();

请提供一些建议。

1 个答案:

答案 0 :(得分:0)

试试这个

WebView webView = (WebView) rootView.findViewById(R.id.webView);
webView.clearCache(true);