Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I design and implement password authentication for IOS?

I have what seems to be a simple issue but I can't find a solution. I have spent hours trying to find an example that shows how to build a view, allow a user to enter a password, authenticate the password and return the view to a designated view. I have found a lot a great resources on bits and pieces, but they all are somewhat vague on how to authenticate the password and then send the user to a designated view.

This seems to be the best solution to my problem, which is: I have several pdfs that I need to password protect in my iPad app.

like image 409
Keith W Avatar asked Aug 22 '11 15:08

Keith W


1 Answers

Issue1: Prompt for userName and Password

Present a view modally. if username/password combination is correct, dismiss the modal view. alternatively, you can use an alert with textfields.

Issue2: Store username/password in a secure way

Use key chain as suggested in the other answer. USage of key chain is as simple as using NSUserDefaults with Carlbrown's PDKeychainBindingsController. You can find it at the below link

https://github.com/carlbrown/PDKeychainBindingsController

EDITED to add info requested in comment:

Assuming you are using a custom view controller for login prompt, you have to do something like this when you want to prompt for password. it can be in your application didFinishLaunchingWithOptions.

LoginViewController *controller = [LoginViewController alloc];
            [self presentModalViewController:controller animated:YES];
                        [controller release];

Then in your LoginViewController, you have to do something like this.

  PDKeychainBindings *keyChain =[PDKeychainBindings sharedKeychainBindings];
            if ([[keyChain objectForKey:@"User Name"] isEqualToString:userName] && [[keyChain objectForKey:@"Password"] isEqualToString:passWord] ) {
                [self dismissModalViewControllerAnimated:YES];
            }else {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"ERROR" message:@"Wrong User Name and/or Password\nEnter Login Information Again"
                                                               delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
                [alert show];
                [alert release];
                  }

Please note that the strings userName and PassWord are captured from your textfields in login view controller.

like image 196
Jose Cherian Avatar answered Nov 15 '22 07:11

Jose Cherian