-1

I have 2 web pages, login page and start page. When user logged in through login page, it is redirected to start page if username and password are correct. My problem is, how to do the login process hidden using pre-defined username and password and show only start page to the user.

I tried loading url to webView as myloginPagePostMethodAction?username=un&password=ps. But it didn't work. I tried to use httpClient to login and show the result in webView. It shows start page but with no javascript. And when I tried to use links in that page it says that I'm not logged in.

Please help..!

Ramesh-X
  • 4,853
  • 6
  • 46
  • 67

1 Answers1

1

Kind of low-tech, you could let javascript enter the username and password when hitting the startpage: How to enter password automatically in Webview.

The code example looks like this:

    webView.getSettings().setJavaScriptEnabled(true);   

    webView.loadUrl("http://your.url");

    webView.setWebViewClient(new WebViewClient() {

        public void onPageFinished(WebView view, String url) {
            view.loadUrl("javascript:document.getElementsByName('school')[0].value = 'schoolname'");
            view.loadUrl("javascript:document.getElementsByName('j_username')[0].value = 'username'");
            view.loadUrl("javascript:document.getElementsByName('j_password')[0].value = 'password'");

            view.loadUrl("javascript:document.forms['login'].submit()");
        }
    });

I think a more robust solution would be to generate some kind of session token once a succesful login has been performed and use that to avoid having to login.

That is not something I know a lot about though, so cannot go into details of how to do that.

Community
  • 1
  • 1
cYrixmorten
  • 7,110
  • 3
  • 25
  • 33