Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. static func loadPassProtected(key: String, context: LAContext? = nil) -> Data? {
  2. var query: [String: Any] = [
  3. kSecClass as String : kSecClassGenericPassword,
  4. kSecAttrAccount as String : key,
  5. kSecReturnData as String : kCFBooleanTrue,
  6. kSecAttrAccessControl as String: getPwSecAccessControl(),
  7. kSecMatchLimit as String : kSecMatchLimitOne]
  8.  
  9. if let context = context {
  10. query[kSecUseAuthenticationContext as String] = context
  11.  
  12. // Prevent system UI from automatically requesting password
  13. // if the password inside supplied context is wrong
  14. query[kSecUseAuthenticationUI as String] = kSecUseAuthenticationUIFail
  15. }
  16.  
  17. var dataTypeRef: AnyObject? = nil
  18.  
  19. let status = SecItemCopyMatching(query as CFDictionary, &dataTypeRef)
  20.  
  21. if status == noErr {
  22. return (dataTypeRef! as! Data)
  23. } else {
  24. return nil
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement