There should be a registration page with Full Name, User Name, Password, Email and Register Button.
When we Click on Register Button we then go to Login Page where it validate the username and password that we created in registration page using NSUserDefaults.
Now if we give right credentials then it should redirect to logout page and when we next time open the app it should directly redirect to logout page.
Data Should be stored locally using NSUserDefaults(value should be stored in string format).
Login view controller .h
#import <UIKit/UIKit.h>
@interface ViewController2 : UIViewController
@property(strong, nonatomic)NSString *dataString;
@property(strong, nonatomic)NSString *dataString2;
@property (strong, nonatomic) IBOutlet UILabel *lblOutput;
@property (strong, nonatomic) IBOutlet UITextField *inputTxt1;
@property (strong, nonatomic) IBOutlet UITextField *inputTxt2;
- (IBAction)btnAction:(id)sender;
@end
Login view controller .m
#import "ViewController2.h"
@interface ViewController2 ()
@end
@implementation ViewController2
- (void)viewDidLoad {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *firstName = [defaults objectForKey:@"firstName"];
NSString *lastName = [defaults objectForKey:@"lastname"];
firstName = _inputTxt1.text;
lastName = _inputTxt2.text;
[super viewDidLoad];
NSLog(@"%@",self.dataString);
NSLog(@"%@",self.dataString2);
self.navigationItem.title = @"Login Page";
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)btnAction:(id)sender {
NSString *firstName = [_inputTxt1 text];
NSString *lastName = [_inputTxt2 text];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:firstName forKey:@"firstName"];
[defaults setObject:lastName forKey:@"lastname"];
[defaults synchronize];
// [Defaults setObject:@"Eezy"forKey:@"iOS"];
NSLog(@"%@",[defaults stringForKey:@"firstName"]);
NSLog(@"%@",[defaults stringForKey:@"lastName"]);
if ([self.dataString isEqualToString:[defaults objectForKey:@"firstName"]] && [self.dataString2 isEqualToString:[defaults objectForKey:@"lastName"]])
{
NSLog(@"goog");
[self performSegueWithIdentifier:@"segueToNextPage2" sender:self];
}
else
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Hey Listen" message:@"Wrong User Name or Password" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
}
}
@end
The problem is that I have passed the value from registration page but when I am storing it in NSUserDefault then it is storing the value of username but in case of password it is showing null value.