2009-10-08 12 views

答えて

19

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).

his blog

+0

はプレーンテキストで返されるパスワードですか? – pxl

+0

私は私のプロジェクトにそのクラスを追加するとき、私はから参照、そのよう 「_kSecAttrAccount」として奇妙なエラーの束を得る:+ [SFHFKeychainUtils deleteItemForUsername:andServiceName:エラー:SFHFKeychainUtils.o から参照「_SecItemDelete」、で_kSecAttrAccount $ non_lazy_ptr参照] SFHFKeychainUtils.oで "_kSecReturnAttributes"、:_kSecReturnAttributes $ non_lazy_ptr SFHFKeychainUtils.o で "_kSecClass"、から参照:_kSecClass $ non_lazy_ptr SFHFKeychainUtils.o "_kSecClassGenericPassword" で、から参照:SFHFKeychainUtils.oに_kSecClassGenericPassword $ non_lazy_ptr – Jason

+0

ユーザー名の値を保存するためのベストプラクティスは何ですか? ServiceNameだけを指定すると、ユーザ名を見つける方法はありますか? – cksubs

5

keychainを参照してくださいあなたが探しているものです。

+2

そのリンクはMac OS Xのキーチェーン用です。 iPhone版のリンクは少し異なります(http://developer.apple.com/IPhone/library/documentation/Security/Conceptual/keychainServConcepts/02concepts/concepts.html –

+0

ありがとう)。これを修正しました。 –

3

キーチェーンを使用してください。ここはsome codeです。非常に簡単です。デバイスとシミュレータで動作します。

2

Generic Keychainソースの例を参照してください。それはIMHOに行く方法です

関連する問題