I need help for an if-else statement to check if the username and password matches. There’ll be two text fields where the user inputs the username and password, a Submit button to login the user and also a label below it to display an error message if the username and password isn’t valid. Once username and password is valid, the modal view will dismiss and take the user to the main page of the app. Below is the valid username and password:
Username: user1
Password: test123
My existing code below doesn’t work.
if (usernameTextField.text == @"user1" && passwordTextField.text == @"test123")
{
statusLabel.text = @"Success!";
[self dismissModalViewControllerAnimated:YES];
}
else
{
statusLabel.text = @"Incorrect. Please try again";
}
Any help would be appreciated. Thanks! 🙂
I dont think there’s anything wrong in your code. However, try comparing the string values with the isEqualToString method and not the ==.
Also, check that the textfields are connected in the nib.