I am working on an iPhone/iOS app. It have a login page with two text fields "username" & "Password" 3rd option is "Remember me" Now i want to save username & password when "remember me" is checked. Please tell me how can I save password & username. Plz give me an easiest way.
Asked
Active
Viewed 3,461 times
1
-
Duplicate of http://stackoverflow.com/questions/5752468/how-to-get-the-nsuserdefault-value-in-other-viewcontrollers – Chetan Bhalara Apr 22 '11 at 10:04
-
http://stackoverflow.com/questions/6972092/ios-how-to-store-username-password-within-an-app Take a look here. – Atul Goyal Dec 07 '12 at 14:56
-
Store the username & password in [Keychain Services Tasks for iOS](http://developer.apple.com/library/mac/#documentation/Security/Conceptual/keychainServConcepts/iPhoneTasks/iPhoneTasks.html). – Black Frog Apr 22 '11 at 10:04
-
You can use keychain to store sensitive data... I've posted some other answers about this topic and you can find an answer reading them, [here](http://stackoverflow.com/questions/5448525/what-is-the-best-way-for-saving-username-and-high-score/5448815#5448815) and [here](http://stackoverflow.com/questions/4309110/error-saving-in-the-keychain-with-iphone-sdk/5625186#5625186). – matteodv Apr 22 '11 at 10:09
1 Answers
2
Assume username and password are text fields.
NSUserDefaults *pref=[NSUserDefaults standardUserDefaults];
[pref setObject:username.text forKey:@"username"];
[pref setObject:password.text forKey:@"password"];
When you want to access the saved values do:-
NSString *username,*password;
NSUserDefaults *prefs= [NSUserDefaults standardUserDefaults];
username=[prefs objectForKey:@"username"];
password=[prefs objectForKey:@"password"];

Gypsa
- 11,230
- 6
- 44
- 82