Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cis4life

macrumors regular
Original poster
Apr 4, 2008
216
66
Code:
-(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)
 
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.
 
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.