Programmatically logging into a website with a saved username and password

One of the features of the application that I am doing is to register a user on our Campus Portal website. For ease of use, the user can enter the username and password into the application once, and it will be saved for all future logins. When the user clicks the button, information will be automatically sent to log in, and the website will be displayed in UIWebView .

Say the username and password are stored in NSString . How can I use this data to enter this website programmatically and display the page in UIWebView ?

I know little about publishing and forms, so any help is appreciated.

Will there be something like this Stackoverflow Answer Help?

Here is the wrapper of my code for this

 - (IBAction)btnGo:(id)sender { username = usernameField.text; password = passwordField.text; if (saveSwitch.isOn) { //Save data if the user wants AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; usernameSaved = username; passwordSaved = password; [appDelegate.listOfPortalCredentials replaceObjectAtIndex:0 withObject:usernameSaved]; [appDelegate.listOfPortalCredentials replaceObjectAtIndex:1 withObject:passwordSaved]; } //Insert username and password to web form, log in to portal //This is where I need help } 

Edit:

Thanks to Karthik, I was able to find the HTTP message using Firebug. This gave me:

 appName=ridgefield&portalUrl=portal%2Fridgefield.jsp%3F%26rID%3D0.18423783694092&username=<username>&password=<password>&B1=Log+In&url=portal%2Fmain.xsl%3FrID%3D0.6845596700302482&lang=en 

where they represent the valid username and password. I believe that this is what I need. Using this, how can I display the login page of the UIWebView ? Do I just need to load the above URL into a UIWebView ?

+3
source share
1 answer

Use UIWebView and do http POST for https://ic.ridgefield.org/campus/verify.jsp with username and password.

To understand how this works, install Firebug in the Firefox browser and go to the "Net" tab on firebug, and then open your website and enter your username / password.

You must imitate this action with code. (I always get an invalid username or password from the server, because I do not have an account, and I try to use some random ones, and since there is no registration on the site, there is no way for me to verify this)

 UIWebView* webView = [[UIWebView alloc] initWithFrame:self.view.frame]; [self.view addSubview:webView]; NSString* username = @""; NSString* password = @""; NSURL* url = [NSURL URLWithString:@"https://ic.ridgefield.org/campus/verify.jsp"]; NSString* body = [NSString stringWithFormat:@"appName=ridgefield&username=%@&password=%@", username, password]; NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:30]; request.HTTPMethod = @"POST"; request.HTTPBody = [body dataUsingEncoding:NSStringEncodingConversionAllowLossy]; [webView loadRequest:request]; 
+3
source

Source: https://habr.com/ru/post/1488398/


All Articles