Example #1
0
        private void LoginButton_Click(object sender, EventArgs e)
        {
            _ = new User();
            User_Service userService = new User_Service();

            if ((UsernameTxtBox.Text.Length < 1) || (PasswordTxtBox.Text.Length < 1))
            {
                MessageBox.Show("Missing credentials!");
            }
            else
            {
                if (userService.IsUsernamePresent(UsernameTxtBox.Text))
                {
                    User user = userService.GetUserByName(UsernameTxtBox.Text);
                    if (PasswordTxtBox.Text.Equals(user.password))
                    {
                        this.Hide();
                        new Dashboard(user).Show();
                        user.rememberMe = RememberMeBox.Checked;
                    }
                    else
                    {
                        MessageBox.Show("Incorrect username or password"); //password doesn't match
                    }
                }
                else
                {
                    MessageBox.Show("Incorrect username or password"); //username does not exist in the db
                }
            }
        }
Example #2
0
        private User CheckUser()                                //checks if user with username is
        {                                                       //present in db and returns User object
            _ = new User();
            User_Service userService = new User_Service();

            if (userService.IsUsernamePresent(UsernameTxtBox.Text))
            {
                User user = userService.GetUserByName(UsernameTxtBox.Text);
                return(user);
            }
            else
            {
                return(null);
            }
        }
Example #3
0
        //Checks if the username is already in the database.
        private bool isUserValid()
        {
            if (service.IsUsernamePresent(txtUsername.Text))
            {
                MessageBox.Show("Username is already taken please pick another one", "Invalid username", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
            else if (String.IsNullOrWhiteSpace(txtUsername.Text) || String.IsNullOrWhiteSpace(txtPassword.Text) || String.IsNullOrWhiteSpace(txtName.Text) || String.IsNullOrWhiteSpace(txtEmailAddress.Text) || String.IsNullOrWhiteSpace(txtlastName.Text))
            {
                MessageBox.Show("Please fill all the fields properly(all fields must be filled", "Missing field", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
            else if (txtPassword.Text.Length < 4 || txtUsername.Text.Length < 4)
            {
                MessageBox.Show("Username and password field must have more than 4 characters", "Invalid username/password", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }

            return(true);
        }