如何在Keychain中存储用户名和密码,并通过alertView验证它们 [英] How to Store Username and password in Keychain and verify them through alertView

查看:76
本文介绍了如何在Keychain中存储用户名和密码,并通过alertView验证它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在钥匙串中存储用户名和密码,并通过alertview验证它们。有人有代码吗?

I want to store a username and password in keychain and verify them through an alertview. Does anyone have code for that?

我这样做是因为应用程序是内部的,我希望应用程序商店接受我的应用程序。

I am doing this because the apps are in-house and I want my apps to be accepted by app store.

推荐答案

NSString *username = @"yourUserName";
NSString *password = @"yourPassword";
KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"TestAppLoginData" accessGroup:nil];

// Store username to keychain
[keychain setObject:username forKey:(id)kSecAttrAccount];

// Store password to keychain
[keychain setObject:password forKey:(id)kSecValueData]; 


// Get username from keychain (if it exists)
NSString *username = [keychain objectForKey:(id)kSecAttrAccount];
NSLog(@"username: %@", username);


// Get password from keychain (if it exists)  
NSString *password = [keychain objectForKey:(id)kSecValueData];
NSLog(@"password: %@", password);

下载 KeychainItemWrapper 表格此处

这篇关于如何在Keychain中存储用户名和密码,并通过alertView验证它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆