我想创建一个用户必须登录的应用程序。我想询问使用NSUserDefaults或CoreData是否更好更安全?或者有更安全和更好的方法吗?
修改
我如何实际检查密码是否适合特定用户?我现在拥有的是:
@IBAction func loginPressed(sender: AnyObject) {
if(txtUsername.text == "" || txtPassword.text == "" || txtUsername.text!.characters.count < 5 || txtPassword.text!.characters.count < 6){
let alert = UIAlertController(title: "Failure", message: "Too short password or username", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}else if(txtUsername.text!.characters.count > 5 && txtPassword.text!.characters.count > 6) {
//Here i want to check if the password for the specific user is the right one
}
}
@IBAction func registrationPressed(sender: AnyObject) {
username = txtUsername.text!
password = txtPassword.text!
do {
try
Locksmith.saveData(["Password" : password], forUserAccount: username)
}catch{
print("ERROR");
}
}
答案 0 :(得分:0)
在我看来,你不应该使用任何这些框架,而是在Github上下载这个“Keychain”框架。它使用加密技术来存储要保存在Keychain文件系统中的持久数据。
点击此链接下载课程。
答案 1 :(得分:0)
您应该使用iOS Keychain。来自Apple's iOS Security Guide:
许多应用程序需要处理密码和其他短而敏感的数据位,例如 作为键和登录令牌。 iOS钥匙串提供了一种存储这些项目的安全方式
有关钥匙串的更多信息,请参阅Apple's documentation。如果您正在寻找围绕此功能的方便的Swift包装器,我建议Locksmith。