Reputation: 41
I am having login view & after login some list is shown...so i want to save username & password so that login view does not appear once if login made with correct ID,password directly it will show the list
Upvotes: 0
Views: 2845
Reputation: 1484
NSUserDefaults
is just a handy way designed for customize app's preferences. In normal situation, an app will stay in it's own sandbox and therefore other apps won't be able to access it.
However it is not the best choice to do so. It's not good practice. What you really need is keychain and see here for apple's sample code for it, it's much safer in terms of security.
Upvotes: 1
Reputation: 1398
there are multiple ways to save user name and password.. You can save in UserDefalt as above answer. also you can save in plist.
Upvotes: 0
Reputation: 4276
As others have suggested, you can use NSUserDefaults
.
If you are storing the password, then I would suggest you also add a level of security to this. You could use Secure NSUserDefaults (I've not used this personally, but seen a few people reporting it being useful). You can find that here
Or you can use the KeyChain API
Upvotes: 3
Reputation: 4551
You can save this in the NSUserDefaults like this :
NSUserDefaults *userDefaults = [NSUserDefaults standardDefaults];
[userDefaults setBool@"YES" forlkey@"userDidLogin"];
And you test like this :
NSUserDefaults *userDefaults = [NSUserDefaults standardDefaults];
if([userDefaults boolForKey:@"userDidLogin"])
{
.... // Go to the list View
}
This is just an indication, if you would like to put it to work , you should show your code how you implement the implémentation of login interface
Upvotes: 1
Reputation: 80271
If you do not care about encryption, you could save these very simply with
[[NSUserDefaults standardUserDefaults] setValue:@"username" forKey:@"username"];
[[NSUserDefaults standardUserDefaults] setValue:@"secret" forKey:@"password"];
and check those during program startup with
if (![[NSUserDefaults standardUserDefaults] valueForKey:@"username"]) {
// show the login screen
}
Upvotes: 3
Reputation: 323
you may use NSUserDefaults Apple Documentation about NSUserDefaults
Upvotes: 2