2009-10-08 10 views

Odpowiedz

19

Użyj breloczka Apple.

+ (NSString *) getPasswordForUsername: (NSString *) username andServiceName: (NSString *) serviceName error: (NSError **) error; 

+ (void) storeUsername: (NSString *) username andPassword: (NSString *) password forServiceName: (NSString *) serviceName updateExisting: (BOOL) updateExisting error: (NSError **) error; 

The first method allows you to request the password associated with an existing username for a particular service name (I’ve just been using the name of my app as a service name). The second allows you to store a username/password/service name combo, and allows you to specify whether or not the appropriate keychain item should be updated with the provided password if an existing one is found that matches the username and service name pair. The last parameter of each is a reference to an NSError object which will contain lower level error information if something goes wrong (and be nil if it does not).

Więcej informacji można znaleźć his blog

+0

to hasło zwrócone w postaci zwykłego tekstu? – pxl

+0

kiedy dodać tę klasę do mojego projektu mam kilka dziwnych błędów takich jak „_kSecAttrAccount”, odwołuje się od: _kSecAttrAccount $ non_lazy_ptr w SFHFKeychainUtils.o „_SecItemDelete”, odwołuje się od: + [SFHFKeychainUtils deleteItemForUsername: andServiceName: error: ] w SFHFKeychainUtils.o "_kSecReturnAttributes", przywoływane z: _kSecReturnAttributes $ non_lazy_ptr w SFHFKeychainUtils.o "_kSecClass", przywoływane z: _kSecClass $ non_lazy_ptr w SFHFKeychainUtils.o "_kSecClassGenericPassword", przywoływane z: _kSecClassGenericPassword $ non_lazy_ptr w SFHFKeychainUtils.o – Jason

+0

Jaka jest najlepsza praktyka przechowywania nazwy użytkownika? Czy istnieje sposób na znalezienie jakichkolwiek usernamees, biorąc pod uwagę tylko ServiceName? – cksubs

5

keychain jest to, czego szukasz.

+2

Ten link jest dla pęku kluczy Mac OS X. Oto link do wersji na iPhone'a (są nieco inne): http://developer.apple.com/IPhone/library/documentation/Security/Conceptual/keychainServConcepts/02concepts/concepts.html –

+0

O, dzięki. Naprawiono to. –

3

Użyj pęku kluczy, tutaj jest some code, aby było bardzo proste. Działa na urządzeniu i symulatorze.

Powiązane problemy