0

I'd like to autologin a user. When he puts in his credentials (username, password) the first time, it gets saved in the keychain. Now when the user restarts the app, he should get redirected to his account-information without seeing the login screen..

I guess I have to start this in AppDelegate, right?

Any idea? Thanks in advance.

filou
  • 1,609
  • 5
  • 26
  • 53

2 Answers2

1

To answer the question: if you want to auto-login with keychain data, use the free framework "SFHFKeychainUtils". It saves username, password and servicename in keychain. if you want to retrieve it, just save the username in NSUserDefaults and you can get the password with ease.

Here we go:

SiFi HiFi Framework: https://github.com/ldandersen/scifihifi-iphone/tree/master/security

SiFi Hifi Framework (ARC compatible): https://stackoverflow.com/a/10348964/1011125

How to use SFHFKeychainUtils: http://gorgando.com/blog/technology/iphone_development/simple-iphone-tutorial-password-management-using-the-keychain-by-using-sfhfkeychainutils

Community
  • 1
  • 1
filou
  • 1,609
  • 5
  • 26
  • 53
-4

IOS device doesn't have the concept of keychain (as far as I know).

What you can do to avoid subsequent login screen is this: Once you successfully login, save a boolean variable in your userdefaults. I hope you are familiar with User Defaults data, which can store small amount of datan for your app. Consider it as a database which persists across app executions. Once you open your app next time, read this variable and if it says logged in, don't go to login.

I hope this works for you.

zolio
  • 2,439
  • 4
  • 22
  • 34
  • iOS does in fact have a keychain, but it is difficult to use and there is no point if the user's credentials will not be checked a second time anyway. This method is simpler. By the way though, most databases persist ;). – borrrden Apr 22 '12 at 23:41
  • Thanks Borrden for the clarification, especially about the keychain. – zolio Apr 23 '12 at 00:24
  • Thank you guys. User Defaults is nothing new to me.. just thought keychain would be much more secure (but it's heavy too :D). how can I compare the results (isEqual-function?) and where do I have to put it (AppDelegate?). – filou Apr 23 '12 at 09:07