Maximilian Litteral
Maximilian Litteral

Reputation: 3089

UIWebView saving username and password

i got the username and password using javascript, but the code wont work for all sites. gmail uses a different id's than face books, and many sites probably do also, so how can make the code work for any site logging in?

heres how it gets the username/password now:

if (navigationType == UIWebViewNavigationTypeFormSubmitted) {
    //works for gmail
    NSString *username = [WebView stringByEvaluatingJavaScriptFromString:@"document.getElementsByName('Email')[0].value"];
    NSString *password = [WebView stringByEvaluatingJavaScriptFromString:@"document.getElementsByName('Passwd')[0].value"];

    //works for facebook?
    //NSString *username = [WebView stringByEvaluatingJavaScriptFromString:@"document.getElementsByName('email')[0].value"];
    //NSString *password = [WebView stringByEvaluatingJavaScriptFromString:@"document.getElementsByName('pass')[0].value"];
    NSLog(@"username is %@\npassword is %@",username,password);
}

so i just want to know how to get the username and password for any site the user logs into so i can make it save, and then auto-fill when they go back and it is logged out so its an easy login.

Upvotes: 2

Views: 1777

Answers (2)

DivineDesert
DivineDesert

Reputation: 6954

To Get all text fields you can place a js query like this

document.querySelectorAll("input[type='text']")

Hope this help. :)

Also to get more details, refer this post

Upvotes: 2

romo
romo

Reputation: 1990

If you want it to work for ANY site, you're going to have to do something completely different. Perhaps create an array of sites and then store the fields to that object. You could search for each "password" input and then try to move up to the previous input since most of the time it's username then password fields.

But you won't be able to get it to work for every site out there.

Upvotes: -1

Related Questions