I have a login-screen in my iOS app.
The username and password will be saved in the NSUserDefaults
and be loaded into the login-screen again when you enter the app again (of course, NSUserDefaults
are permanent).
Now, the user have the possibility to disable the username/password saving feature.
So the NSUserDefaults
will be cleared then.
But In my app I need this username/password for database queries for the user.
So: Where to store the data except NSUserDefaults
?
(This place can / should be deleted when the user quit the app or logout).
If you are having an issue retrieving the password using the keychain wrapper, use this code:
try this one:
may it will help.
If you need an ARC version of the wrapper here is the link https://gist.github.com/1170641 Thanks to
To update this question:
For those using Swift checkout this drag and drop swift implementation by Mihai Costea supporting access groups:
https://github.com/macostea/KeychainItemWrapper.swift/blob/master/KeychainItemWrapper.swift
Before using the keychain: consider twice before storing passwords. In many cases storing an authentication token (such as a persistence session id) and the email or account name might be enough. You can easily invalidate authentication tokens to block unauthorized access, requiring the user to login again on the compromised device but not requiring reset password and having to login again on all devices (we are not only using Apple are we?).
For swift you can use this library:
https://github.com/jrendel/SwiftKeychainWrapper
It supports all versions of swift.
I looked at using KeychainItemWrapper (the ARC version) but I didn't find its Objective C wrapper as wholesome as desired.
I used this solution by Kishikawa Katsumi, which meant I wrote less code and didn't have to use casts to store NSString values.
Two examples of storing:
Two examples of retrieving