0
votes

I am new to iphone. I am working on my first app. I have a login view,which contains username and password textfields. I try to validate the login page with the following code.but it's not working. Every time,alert view is displaying,What can i do now? Is there any suggestions for this or modified code?

- (IBAction) login: (id) sender
{
NSString *lakshmi;
NSString *narayana;

NSLog(@"login %@",usernameField.text);
if ((usernameField.text== lakshmi)&& (passwordField.text==narayana) )
{
[self.view addSubview:Link_view];
NSLog(@"sucess");
}
else {

NSLog(@"INVALID");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Please Enter User Name & Password"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

[alert show];
[alert release];
}
2

2 Answers

2
votes

There seem to be several problems; the most glaring being your comparison between two pointers 'usernameField.text == lakshmi'. My guess is, you want to compare the string values contained in those objects? If so, you should be doing something like '[usernameField.text isEqualToString:@"lakshmi"]'.

0
votes
  • You haven't initialised the username and password data, so they're filled with junk or are both nil.
  • You shouldn't compare strings directly with the equality operator - that tests for identity. Use -[myString isEqualToString: otherString] instead.
  • Don't store your password in the app binary, as it will be trivial to extract. Use Keychain Services.