如何从iphone应用程序检索钥匙链



在用户登录时将密码存储到keychain中。现在我正在修改密码页面。我想对比一下钥匙扣密码和旧密码。如何检索钥匙串密码?

我使用ASIHttpRequest来验证用户。ASIHttpRequest将密码存储在keychain中。

[request setUseKeychainPersistence:YES];
[request setShouldPresentAuthenticationDialog:TRUE];
[request setShouldPresentCredentialsBeforeChallenge:TRUE];

有人能帮助我如何从Keychain获得存储的密码吗?

既然您使用的是ASIHTTPRequest,那么您可以在ASIHTTPRequest.h中使用它的钥匙链接口:

// Return credentials from the keychain
+ (NSURLCredential *)savedCredentialsForHost:(NSString *)host port:(int)port protocol:(NSString *)protocol realm:(NSString *)realm;

在该文件中还有几个其他的例程应该是感兴趣的。搜索"keychain"

下面这篇关于keychain的简单博客文章帮助我从iphone应用程序中存储和检索keychain值。正如Rob Napier对ASIHttpRequest框架的回答,但我发现它有点复杂,我开始使用苹果KeychainItemWrapper类,它很容易实现。我将此标记为对我问题的回答。

最新更新