How to tell if a user is logged on

Source: Internet
Author: User

iOS: How to verify the user after login (auto login)?

iphone iOS Xcode autologin
I want to automatically log in to the function. Therefore, when the application is opened, he is delegated to a "login screen". When he is logged in, he should be directed to his account. I call this the "Account screen". Now, when restarting the application, he should get directed directly to his account and not see the "Login screen". The login function is already working in my project (and the password is saved in Userdefault) codego.net, but I close the application and I want to log in again. So my question is: how to automatically or better say: How do I check the data (saved in Userdefault) is in the database (MySQL)? Thank you in advance.
This address: codego.net/447673/

--------------------------------------------------------------------------------------------------------------- ----------
1.  for priority login, you save the credentials on the iphone keychain. When the application is opened again, you check the credentials present in the keychain, and if so, your code should call the login logic and do automatic login and login after the screen enters the picture. If not, then you should display the login screen. You can do this logic in Appdelegates applicationdidfinishlaunching. Click the Logout button codego.net, from credential keychain priority, and return to login controller. Simply add the login credentials in the keychain log and delete it only by clicking the logout button. Exit the application without exiting, and then the credentials will still be in the keychain, and you can retrieve them back to the application. Editor: I think I have to add something. If your login logic requires (such as your Web request, or will login logic code in your login Viewcontroller instead of applicationdelegate, any activity LEDs in the automatic logon process. Editor: I edited the complete answer instead of nsuserdefaultkeychain. This thread explains why.  
2.  at the same time save and password, it is highly should be saved in keychain, not nsuserdefaults. Please refer to this post to better understand:  
3.  to answer this question: If you want to automatically log in with keychain data, use the free "sfhfkeychainutils". It saves the password and keychain. If you want to retrieve it, just save it in Nsuserdefaults, you can get the password easily. Here we go: Sifi audio Sifi Audio (how to sfhfkeychainutils: 
4.  nsuserdefaults and Sskeychain. Nsuserdefaults Store the Sskeychain to store the password. This is the voucher saved by the code

NSString *user = self.username.text;NSString *password = self.pass.text;[SSKeychain setPassword:password forService:@"achat" account:user];NSUserDefaults *dUser = [NSUserDefaults standardUserDefaults];[dUser setObject:user forKey:@"user"];[dUser synchronize];

This is the code to retrieve the credentials

NSUserDefaults *eUser = [NSUserDefaults standardUserDefaults];NSString *savedUser = [eUser objectForKey:@"user"]; if (!savedUser) {  UIAlertView *uhoh = [[UIAlertView alloc] initWithTitle:@"Oops!" message:@"Please enter your username and password." delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];  [uhoh show]; } else {   NSString *savedPass = [SSKeychain passwordForService:@"achat" account:savedUser];   self.username.text = savedUser;   self.pass.text = savedPass;   }

How to tell if a user is logged on

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: info-contact@alibabacloud.com 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.