How can we store a username-password combination in keychain in encrypted format
I suggest you to store the password, using the login as a key. something like : acccount_test@test.com / password
.
You can encode the md5
value of the passcode to improve security too
ios: Add new password to iCloud Keychain
After googling for a while, I found the solution here:
https://developer.apple.com/documentation/security/1617986-secaddsharedwebcredential
So apparently SecItemAdd only adds passwords to iOS keychain which is used to store persist sensitive data for the app.
Simple way to store and read a password in apple keychain?
You are storing password as a string inside keychain. I will modify storeKeychain() method
private func storeKeychain(username: String, password: String) throws -> Any? {
let credentials = Credentials.init(username: username, password: password)
let data = credentials.password.data(using: .utf8)!
// store password as data and if you want to store username
let query: [String: Any] = [kSecClass as String: kSecClassGenericPassword,
kSecAttrAccount as String: username,
kSecValueData as String: data]
let status = SecItemAdd(query as CFDictionary, nil)
guard status == errSecSuccess else {
throw KeychainError.unhandledError(status: status) }
return status
}
Check if it works.
Related Topics
Change the iOS Keyboard Layout to Emoji
Uitableview Footer, Stop from Floating Over Content
Code Sign Error:Bundle Format Unrecognized, Invalid, or Unsuitable
Failed to Emit Precompiled Header for Bridging Header
Swift3 iOS - How to Make Uitapgesturerecognizer Trigger Function
How to Send Data Back by Popviewcontrolleranimated for Swift
React-Native iOS App Not Showing Static/Local Assets (Images) After Deploying
How to Do Some Stuff in Viewdidappear Only Once
How to Know If Cellular Access for My iOS App Is Disabled
The Executable Gets Signed with Invalid Entitlements in Xcode
Xcode 8 :Function Types Cannot Have Argument Label Breaking My Build
How to Dismiss Uialertcontroller When Tap Outside the Uialertcontroller
@Binding and Foreach in Swiftui
Ios9 - This Application Is Modifying the Autolayout Engine from a Background Thread -- Where
Wkwebview Open Links from Certain Domain in Safari
Ios 8.1 Simulator Always Uses Us Keyboard Layout Despite German Hardware Keyboard