2009-10-08 32 views

Trả lời

19

Sử dụng Keychain của 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).

Để biết thêm thông tin, xem his blog

+0

là mật khẩu được trả lại trong văn bản thuần túy? – pxl

+0

khi tôi thêm lớp đó vào dự án của mình, tôi nhận được một loạt các lỗi lạ như "_kSecAttrAccount", được tham chiếu từ: _kSecAttrAccount $ non_lazy_ptr trong SFHFKeychainUtils.o "_SecItemDelete", được tham chiếu từ: + [SFHFKeychainUtils deleteItemForUsername: andServiceName: error: ] trong SFHFKeychainUtils.o "_kSecReturnAttributes", tham chiếu từ: _kSecReturnAttributes $ non_lazy_ptr trong SFHFKeychainUtils.o "_kSecClass", tham chiếu từ: _kSecClass $ non_lazy_ptr trong SFHFKeychainUtils.o "_kSecClassGenericPassword", tham chiếu từ: _kSecClassGenericPassword $ non_lazy_ptr trong SFHFKeychainUtils.o – Jason

+0

Thực tiễn tốt nhất để lưu trữ giá trị tên người dùng là gì? Có cách nào để tìm bất kỳ tên người dùng nào, chỉ được cung cấp cho ServiceName không? – cksubs

5

Các keychain là những gì bạn đang tìm kiếm.

+2

Liên kết đó dành cho móc khóa Mac OS X. Đây là liên kết cho phiên bản iPhone (hơi khác một chút): http://developer.apple.com/IPhone/library/documentation/Security/Conceptual/keychainServConcepts/02concepts/concepts.html –

+0

Ồ, cảm ơn. Sửa lỗi đó. –

3

Sử dụng Keychain, đây là some code để làm cho nó rất dễ dàng. Hoạt động trên thiết bị và trình mô phỏng.

Các vấn đề liên quan