Home > Mobile >  Check for username and password always return false
Check for username and password always return false

Time:11-10

I am currently working on a login form in C# where I am using WPF, and I have made a check to see if the data in the form is valid but for some reason it always returns false.

For context here is my check:

private bool CanExecuteLoginCommand(object obj)
{
    bool validData;
    if (string.IsNullOrWhiteSpace(Username) || Username.Length < 3 || Password == null || Password.Length < 3)
        validData = false;
    else
        validData = true;
    return validData;
}

Does anyone know what is causing it to always return false even though username and password is more than three characters?

I have tried setting the username and password so they are both more than three characters and where expecting it to return true.

CodePudding user response:

Okay I figured it out, the problem was that I forgot to return username and password in these methods

    public string Username 
        { 
            get { return _username; }
            set
            {
                _username = value;
                OnPropertyChanged(nameof(Username));
            }
        }
        public string Password 
        {
            get { return _password; }
            set
            {
                _password = value;
                OnPropertyChanged(nameof(Password));
            }
        }

CodePudding user response:

You're not using the obj argument and did not include the Username or Password declarations. Did you mean to do obj.Username instead?

  • Related