2

I'm newbie to this stack overflow so this is my first question.

I've made a return statement so if this validation return 1, it will open a new window, otherwise, it won't be opened. Here is my code :

private int UserPassValidation()
    {
        if (txtUserName.Equals("admin") && txtPassword.Equals("admin"))
        {
            return 1;
        }
        return 0;
    }

private void LOGIN_BUTTON_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        if (UserPassValidation() == 1)
        {
            try
            {
                WindowView objWindowView = new WindowView();
                objWindowView.ShowDialog();
            }
            catch (System.Data.EntityException)
            {
                MessageBox.Show("Entity Exception", "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        else
        {
            MessageBox.Show("...");
        }
    }

So, there is a "Username and password validation" and sign in button. And then, I insert "admin" on txtusername and admin on txtpassword too.

Then, when i click sign in button, it won't be opened. I don't know why, but it's supposed to be opened.

Oslo Young
  • 31
  • 8

2 Answers2

1

Seems like your comparison is not correct in UserPassValidation method. if txtUserName is a Textbox then you should compair thats Text property. like..

if (txtUserName.Text == "admin" && txtPassword.Text == "admin")
samar
  • 5,021
  • 9
  • 47
  • 71
J R B
  • 2,069
  • 4
  • 17
  • 32
  • it seems work, but txtPassword doesn't have a ".Text" attribute, because txtPassword is a PasswordBox, so it's a compile error. – Oslo Young Mar 13 '14 at 06:13
  • Here i had given answer . http://stackoverflow.com/questions/20186737/password-box-does-not-mask-my-password-wpf/20187687#20187687 – J R B Mar 13 '14 at 06:19
1

Aaaahhhh, finally work! So, this is my solution :

if (txtUserName.Text == "admin" && txtPassword.Password.ToString() == "admin")

Sorry, I'm forgot to tell you that txtPassword is a PasswordBox, but, thank you guys! :D

Oslo Young
  • 31
  • 8