1

I am new to iphone development. In my app, i am using two UITextfield for that registering user ID and password. These user ID and password should be save on iphone device after entered text in textfield by the user. is there any idea to do that without database? otherwise how to do that?

Sivanathan
  • 1,213
  • 3
  • 13
  • 25

3 Answers3

2

You'd rather use the Keychain to store the password and Preferences to store user login.

Search for SFHFKeychainUtils.h (Created by Buzz Andersen on 10/20/08) for a class that allows you to perform simple keychain operation (and being able to perform them on the iPhone Simulator).

To store the user login:

NSString *defaultUsername = ...;
[[NSUserDefaults standardUserDefaults] setObject:myUserName forKey:@"myServiceUserName"];

To store the password:

NSError *wsError;   
NSString *defaultUsername = ...
if (defaultUsername && [defaultUsername length] != 0) {
    [SFHFKeychainUtils storeUsername:defaultUsername andPassword:pass forServiceName:@"MyService" updateExisting:YES error:&wsError];
    if (wsError != nil) {
        NSLog(@"Could not store password into keychain. Error: %@", [wsError localizedDescription]);
    }
} 
dodecaplex
  • 1,119
  • 2
  • 8
  • 10
0

Have a look at the

iPhone Core Data

you will have to go deep but this is the main used layer for Saving Data as you, in your application future would probably like to save much more.

If you only want to save some settings, here's a quick and easy trick:

  • Add a Settings Bundle (Resources) File into your project
  • Compile & Run the project
  • in the iPhone Simulator, open Settings and you will see your application name, dive deep and you'll see that Settings file

The iPhone will do all the UI for you based on that XML file, just search on all possibilities that you can have, if you still need help, post it here :)

balexandre
  • 73,608
  • 45
  • 233
  • 342
  • 1
    Core data is great, and all iphone developers should familiarise themselves with it, but I think it might be overkill for saving two strings – Rob Fonseca-Ensor Apr 27 '10 at 09:41
  • I answered it thinking that he will start by `UserId` and `Paswword`, sooner or later he will like to add more and more, or even actual data for offline access... Core Data is the best place to start ... otherwise, Settings bundle will do fine :) – balexandre Apr 27 '10 at 09:43
0

You can also use SQL Lite database as local device database..

Swapnil
  • 1,858
  • 2
  • 22
  • 49