Emon
Emon

Reputation: 958

How can i store data into a text file and retrieve it when the application launches again in iphone application development?

At first of all i want to say that i am newer as an iPhone application developer.So please help me. Now, My problem is, I want to make a text file in my iPhone app.If I explain it then I will say that...

When user will login in my app then he/she will give username and password, Now i want to store these data in the text file and text file will store in the documentsDirectory, when this user again lunch the application then automatically he will able to excess the app without any authentication checking if he/she does not logout from the application first time.

1) 1st person --> login [username & password] --> store username and pass into text file because new user --> enjoy application -->logout.

2) 2nd person --> login [username & password] --> store in text file into text file because new user --> enjoy application --> did not logout.

3) 2nd person again ---> will not give username and password directly he/she have to use the application -->logout.

4) 1st person now ---> login [username & password] and check by saved reading text file ---> enjoy application --> logout.

5) 2nd person now ---> login [username & password] and check by saved reading text file ---> enjoy application --> logout.

Now, my question is how can i do this full process.Can i do this using NSUserDefaults standardUserDefualts or i need to make a text file for storing username & password??

Upvotes: 0

Views: 487

Answers (2)

Bill Burgess
Bill Burgess

Reputation: 14154

I would think about storing username/password in the keychain. It is more secure and you won't have to worry about that information getting hacked out of the user defaults plist. If you still want to use a username and password, consider hashing it before storing it. Then if that information gets out (unlikely, but still possible) it won't mean anything to them.

You can actually view the contents of your user defaults from Organizer, the information is just stored as plain text there, so it is not recommended to use this as a way to store username and password.

Upvotes: 0

ader
ader

Reputation: 5393

Yes you can store simple bits of data like these in standardUserDefaults.

I assume that you will check user identity though. e.g.what if user 1 logs in but does not logout and then user2 launches the app?

Personally I would only store the username if you plan for more than one person to access the app on a specific device and I would require the password each time.

set:

[[NSUserDefaults standardUserDefaults] setObject:userNameStr forKey:userName];
[[NSUserDefaults standardUserDefaults] synchronize];

get:

userNameStr = [[NSUserDefaults standardUserDefaults] objectForKey:userName];

Upvotes: 1

Related Questions