iphone - IOS的密码认证如何设计和实现?

标签 iphone ios ipad pdf password-protection

我遇到了一个看似简单的问题,但我找不到解决方案。我花了几个小时试图找到一个示例来展示如何构建 View 、允许用户输入密码、验证密码并将 View 返回到指定 View 。我找到了很多关于点点滴滴的重要资源,但它们都对如何验证密码然后将用户发送到指定 View 有些模糊。

这似乎是我的问题的最佳解决方案,即:我有几个 pdf 文件需要在我的 iPad 应用程序中进行密码保护。

最佳答案

问题1:提示输入用户名和密码

以模态方式呈现 View 。如果用户名/密码组合正确,则关闭模态视图。或者,您可以使用带有文本字段的警报。

问题 2:以安全的方式存储用户名/密码

按照其他答案中的建议使用钥匙串(keychain)。 key 链的使用就像使用 NSUserDefaults 和 Carlbrown 的 PDKeychainBindingsController 一样简单。您可以在下面的链接中找到它

https://github.com/carlbrown/PDKeychainBindingsController

编辑以添加评论中要求的信息:

假设您正在使用自定义 View Controller 进行登录提示,当您想要提示输入密码时,您必须执行类似的操作。它可以在您的应用程序 didFinishLaunchingWithOptions 中。

LoginViewController *controller = [LoginViewController alloc];
            [self presentModalViewController:controller animated:YES];
                        [controller release];

然后在您的 LoginViewController 中,您必须执行类似的操作。

  PDKeychainBindings *keyChain =[PDKeychainBindings sharedKeychainBindings];
            if ([[keyChain objectForKey:@"User Name"] isEqualToString:userName] && [[keyChain objectForKey:@"Password"] isEqualToString:passWord] ) {
                [self dismissModalViewControllerAnimated:YES];
            }else {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"ERROR" message:@"Wrong User Name and/or Password\nEnter Login Information Again"
                                                               delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
                [alert show];
                [alert release];
                  }

请注意,字符串 userName 和 PassWord 是从登录 View Controller 中的文本字段中捕获的。

关于iphone - IOS的密码认证如何设计和实现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7149412/

相关文章:

ios - 无法在 AFNetworking 中获取下载进度

ios - 如何在 Collection View Controller 上添加另一个 ScrollView ?

ios - CoreBluetooth 和 BluetoothManager,设备不是 BLE

ios - 如何显示多个具有相同纬度/经度的 MKPinAnnotation?

iphone - Facebook 墙贴在 Facebook 注册 iOS-facebook SDK 3.2 之后

iphone - 如何强制用户停留在特定的 UITextfield

iphone - 如何将 `UIKeyInput`协议(protocol)与 `UIWebView`控制一起使用?

ios - 在 iOS 中点击关闭设备低电量警报时,应用程序导航到主屏幕

iphone - 为什么不在全新项目(xcode 3.1.4)上调用 dealloc?

ios - UIToolBar 位置到 UINavigationController 的顶部