Encryption will give you some security. The problem is that your program will also need to decrypt the password, which means that the key must be stored in it. This will make it vulnerable to reverse engineering. It is best to use a one-way function (such as a hash) in a password and store this value of the hash function. When the user enters the password, you then apply the one-way function to the password and compare the result with the stored value. Thus, the password cannot be cracked (well, there is always a dictionary attack, but it depends on the strength of the password).
Instead of using NSUserDefaults, you would be better off using iOS Keychain Services . The main goal is the safe storage of user credentials. Apple has already done all the hard work for you. Use it.
source share