check keychain is empty or not at start of app - ios

I am building a password management app using objective c and it has two views, with sign up view being the initial/startup view and login view another.
Once the user registers with the app, i am saving the username and password in keychain.
I want to implement a functionality where, when the app launches, it checks if any user exist and if yes it should not show me sign up screen but instead show me login screen.
However i am not able to check wether keychain is empty or not when the app starts.
Please advice how can i do this functionality?

Related

iOS App, How to set it to one time registration?

I am Developing an App, that needs Registration, After launch Screen it shows Registration Screen. After Registration it allows to move on home Screen, and then any Task can be performed on the App.
Now I want my App to save the username and password into device, and on Launch, Application automatically registers the user.
if registration Successfully Achieved, then it automatically shows HomeScreen.
So my Question is, How do I achieve this?
I am beginner, Any Suggestion will be appreciated.
Thanks in Advance.
You should not to save password on your device. It's very not adviser to do that.
At the login, your API should return a session token. It is this one you have to save on device in Keychain. On launch, just retrieve the token in Keychain to be sure there is a session and go to HomeScreen, otherwise log out the user.
You can use this Lib https://github.com/matthewpalmer/Locksmith
You can use UserDefaults or Keychain.
https://developer.apple.com/reference/foundation/userdefaults
https://developer.apple.com/library/content/documentation/Security/Conceptual/keychainServConcepts/iPhoneTasks/iPhoneTasks.html

Bypass login if user already created account

the reason I am asking this question is because I am not using firebase or parse to create accounts. I have used my own code to use CloudKit to login and so on. My question is, after the first time opening the app, and the user making an account, how can I make sure that the following time they open the app, it bypasses the login page? And then, if they logout, the next time they open the app, it takes them to the login page. How can this be done.
TL;DR how can I track whether or not a user has been logged in, and then open the app to a 2 possible scenes based on whether or not they are or are not logged in.
Firstly, you could keep the user sign in data (like a returned authkey, or a boolean flag) in the Defaults for the app.
Secondly, you could make a "Loading View" where you would check if that data is present.
Lastly, if the data isn't present move him to the login view, else to the main app.

How Do I Force An iOS TouchID To Re-Authorize After Each Access, or Check If It is Unlocked?

OK. I suspect I just need to be directed to the appropriate "M" for "RTFM." I'm not new to iOS, but fairly new to keychain use. I am using a good keychain wrapper called "FXKeychain."
I have an app that includes a login, with a password stored in the default keychain.
I use TouchID to validate the user and fill in the password.
In order to do this, I display a "thumbprint" button, with an IBAction handler that runs the standard code:
self.s_authenticationContext.evaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason: "Yo. Gimmie ur thumb.", reply: self.touchIDCallback)
The issue is, that once it is unlocked, subsequent touches of the button, using the above, skip the alert, and simply fall through.
This is an issue because the same button is displayed, even after the user is validated. I'd like to either:
Re-lock after entering the password, so the user must re-authenticate each time (preferred), or
Display a different button image that indicates the thumbprint is no longer necessary.
That means that I need to:
Find a way to re-lock the TouchID, or
Find out if the user is unlocked.
Any ideas?
Thanks!
It is your authentication context rather than the keychain that is 'unlocked'. If you allocate a new authentication context before calling evaluatePolicy then the touchID dialog will be shown again.
You can, however, actually use touchID to authenticate access to a keychain item directly. The Apple sample code demonstrates how to do this - https://developer.apple.com/library/ios/samplecode/KeychainTouchID/Introduction/Intro.html#//apple_ref/doc/uid/TP40014530-Intro-DontLinkElementID_2

Social login when app becomes active after suspension state

I have been struggling with this question and cannot seem to find a clean answer for. I am using social login in an app I am writing (my first). After the app launch, the user gets authenticated with his choice of a social network, in particular, Facebook. when a user suspends the IOS app for days, and returns to it, the app returns right where the user left off, away from the initial login mechanism and the login viewController. How and where do you attempt to verify if the user Facebook token changed (due to password change) or expired? from what I understand you have to make a social graph api request, but does that mean I have to implement this request in every viewController in my app? I am under the impression that when the app becomes active it will only load the viewController displayed before the suspension. Maybe I am wrong.
your input is greatly appreciated.
Regards
So I do have controller over what I present when an app becomes active. I can simply present in the window the login view controller. I can silently verify the credentials. if pass present the next view controller. if not present the login page for the user interaction.
cheers

Control flow for a webservice-backed iOS App

I'm learning the basics of iOS development, and I'd like to make a simple application that connects to a web service. I've got a lot of experience on the web application side, so I'm comfortable with what kinds of requests the app needs to send/receive etc. The part I'm not sure about is what the big picture architecture of a service-backed mobile application looks like.
When my application runs, I have one major requirement: the user must authenticate into the web service. The web service can send back a token and the app can use this for all subsequent requests. I want the user to be able to log in once, and for the app to stay logged in (ie the token remains valid for that device) indefinitely unless they log out.
Until the user logs in the application should really just be a login screen. If they log out, the same. Otherwise, they don't need to see the login screen at all.
So my question is, what is the right way to structure this?
In AppDelegate, do I want to make a LoginViewController and set it to the rootViewController? Then if the user is logged in, push to the main view for the rest of the app?
Or do I want to initialize the main part of the app (for instance, a UITabBarController with a few views in it), and check for a token, and then display a modal login screen if no token is available?
What I'm not clear on is what the rootViewController should be for an application like this, and how the app should keep track of whether the user is logged in, and determine what screen to show when the app is opened.
If anyone can give me a high level overview of how such an app should be structured, I'd really appreciate it.
Thanks!
There isn't really a right way to do this, either flow could be appropriate for an application. If I had some UI or data that would be displayed if a user is not logged in then I would use that as the initial rootViewController and use a modal login dialog to force the user to login. On the other hand, if I had nothing to display until a user has logged in then I would setup the login view controller to be the initial rootViewController if the user is not currently logged in.
For keeping track of the user being logged in you should leverage NSUserDefaults to persist the authentication token. Then in the application:didFinishLaunchingWithOptions: call to your app delegate look for this token in NSUserDefaults (and possibly validate it with the server) then set the rootViewController as appropriate.

Resources