Preferences Save user Information

Source: Internet
Author: User
Tags openssl md5 openssl sha1 asymmetric encryption

Preferences to save user information .


<1> If the user logs on successfully, save the user information . The next time directly from the preferences to read the user information, so that users only need to enter an account and password , and then login can not be entered again .

1;. Login successful , save user Information ( preferences )

2;. Enter again to display the information previously saved directly by the user . Avoid repeated user input .

// Preferences store user information

-(void) Savauserinfo


// Instantiation Preference Object ( singleton )

Nsuserdefaults *user = [Nsuserdefaults standarduserdefaults];

// Save user name

[User setobject:selfusername.text forkey:kitusernamekey];

// Save user Password

[User Setobject:pass Forkey:kituserpasskey];

// Sync Save user Information

[User Synchronize];


// load user information in preference settings

-(void) Loaduserinfo


Nsuserdefaults *user = [Nsuserdefaults standarduserdefaults];

if ([User Objectforkey:itusernamekey]) {

self. username.text = [User Objectforkey:itusernamekey];

}if ([User Objectforkey:ituserpasskey]) {

self. password.text = [User Objectforkey:ituserpasskey];



<2> user Login business logic


//<1> user login requires a separate controller because only one login is required (Login.storyboard). The application needs to have a portal : Main.storyboard:app Main Page

//<2> Determine if the user has successfully logged in ( Judging by user information stored in Preferences )

//1> If the user information is stored in the preferences ( indicating that the previous login was successful), go directly to the app Main Page : Main.storyboard

//2> If there is no user information in the preferences ( first login or log off user information ), enter the login interface : Login.storyboard

//<3> If the user logs in successfully, jump to the app Main Page : Main.storyboard. and save the user information in Preferences .

//<4> If the user clicks the logout button , logs off the user information and returns to the landing page .


<3> problem : user password can not be saved in clear text form , need to encrypt the user password before saving !

security Principles for passwords :

1> local and server are not allowed to save the user's password plaintext .

2> on the Network , the transmission of the user's password plaintext is not allowed .

Modern cryptography Anecdotes ! Midway Is. Naval Warfare (AF)

<4> Data encryption Algorithm :

1> symmetric encryption Algorithm : Use the same key for encryption and decryption . Encryption and decryption speed is fast, to ensure that the key security . Suitable for big Data encryption .

2> Asymmetric Encryption Algorithm : use public key encryption , private key decryption . or the public key is decrypted using private key encryption . More secure , but the encryption and decryption speed is slow, suitable for small data encryption .

<5> tips :

OpenSSL: is a strong Secure Sockets Layer cipher library that includes key cryptographic algorithms , common key and certificate encapsulation management functions, and SSL protocols . Provides rich application testing capabilities .

Terminal command :

echo Hello |openssl MD5

echo Hello |openssl SHA1

echo Hello |openssl sha-sha256

echo Hello |openssl sha-sha512


Preferences Save user Information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.