PDA

View Full Version : What won't this work?




cis4life
Jul 11, 2009, 10:45 PM
-(IBAction)loginAction:(id)sender
{
NSString *unStr = [[NSString alloc] initWithString:usernameField.text];
NSString *passStr = [[NSString alloc] initWithString:passwordField.text];

if([unStr compare:@"druser"] && [passStr compare:@"password"])
{
//Load Main View Here
}
else
{
UIAlertView *failAlert = [[UIAlertView alloc]
initWithTitle:@"Login Failed"
message:@"The username and password you supplied were not found in our system, please check your credentials and try again."
delegate:nil
cancelButtonTitle:@"Go Back" otherButtonTitles:nil];

[failAlert show];
[failAlert release];
}
}



The code launches, but IF i type 'druser' and 'password' as the username and password, it launches the else code block??? Maybe I'm missing something?

Also,

I have a UITextField, how do I mask it so that as I input text into it, it comes up like a password (the black circles instead of the actual text)



lucasgladding
Jul 11, 2009, 11:09 PM
You want isEqualToString: rather than compare:. compare: is for sorting purposes, with NSOrderedSame being the result when comparing equal strings. NSOrderedSame is equivalent to 0 or false, hence the else block being called.

The secureTextEntry property is what you need for the password field. It's part of the UITextInputTraits protocol that UITextField conforms to.

cis4life
Jul 11, 2009, 11:26 PM
Thanks a million,

You Da Man. That worked like a charm. (still getting myself around all the ins and outs of coco touch and obj-c)

But that worked like a charm

Cedric