Save username-password with NSUserDefault, how and how much safe?

后端 未结 4 1185
礼貌的吻别
礼貌的吻别 2020-12-19 15:58

I would save a couple of values (username-password) with NSUserDefault.

First: is there a way to save them together (like in an array for example)? Second: is it saf

相关标签:
4条回答
  • 2020-12-19 16:25

    No. It's not safe.

    If you need to store data securely, use the keychain.

    0 讨论(0)
  • 2020-12-19 16:31

    you can use an NSDictionary or NSarray to save your values, and you should also encrypt your data because NSUserDefaults works like a plist which can be accessed by anyone

    0 讨论(0)
  • 2020-12-19 16:36

    Encryption will give you some security. The problem is your program would also have to decrypt the password, which means it must have the key stored in it somewhere. This will make it vulnerable to reverse-engineering. A better approach is to use an one-way function (such as a hash) on the password and store that hash value. When a user enters a password, you then apply the one-way function to the password and compare the result to the stored value. In this manner, the password cannot be compromised (well, there's always a dictionary attack, but that's a matter of password strength).

    Instead of using NSUserDefaults, you would be better off using iOS Keychain Services. It's main purpose is to securely store user credentials. Apple has already done all the hard work for you. Take advantage of it.

    0 讨论(0)
  • 2020-12-19 16:39

    This one is easy to use, works with ARC

    0 讨论(0)
提交回复
热议问题