Ejemplo n.º 1
0
 private void LoginTextBox_KeyPress(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar == 13)
     {
         PassTextBox.Focus();
     }
 }
Ejemplo n.º 2
0
 private void SignInButton_Click(object sender, EventArgs e)
 {
     if (Users.Extant(LoginTextBox.Text))
     {
         User selectUser = Users.GetUser(LoginTextBox.Text);
         if (selectUser.Pass == PassTextBox.Text)
         {
             user         = selectUser;
             DialogResult = DialogResult.OK;
         }
         else
         {
             MessageBox.Show("Неверный пароль", "Ошибка авторизации", MessageBoxButtons.OK);
             PassTextBox.Text = "";
             PassTextBox.Focus();
         }
     }
     else
     {
         MessageBox.Show("Пользователь не найден", "Ошибка авторизации", MessageBoxButtons.OK);
         LoginTextBox.Text = "";
         PassTextBox.Text  = "";
         LoginTextBox.Focus();
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Handle login button event. Send information to server
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void loginButton_Click(object sender, RoutedEventArgs e)
        {
            logger.Info("loginButton_Click");

            if (!Regex.IsMatch(emailAddrTextBox.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
            {
                errorMessage.Content = "Enter a valid email.";
                emailAddrTextBox.Select(0, emailAddrTextBox.Text.Length);
                emailAddrTextBox.Focus();
            }

            else if (PassTextBox.Password.Length == 0)
            {
                errorMessage.Content = "Enter password.";
                PassTextBox.Focus();
            }
            else
            {
                using (new CursorWait())
                {
                    LoginData loginData = new LoginData();

                    loginData.EmailAddress = emailAddrTextBox.Text;
                    loginData.Password     = PassTextBox.Password;

                    LoginResult result = service.UserLogin(loginData);

                    switch (result.Status)
                    {
                    case OperationStatus.Success:
                    {
                        Properties.Settings.Default.email    = emailAddrTextBox.Text;
                        Properties.Settings.Default.password = PassTextBox.Password;

                        Properties.Settings.Default.Save();

                        WelcomePage welcome = new WelcomePage(service, result.NickName, emailAddrTextBox.Text);
                        NavigationService.Navigate(welcome);
                    }
                    break;

                    case OperationStatus.Failure:
                        errorMessage.Content = "Internal server error";
                        break;

                    case OperationStatus.InvalidEmail:
                        errorMessage.Content = "Email address doesn't exist";
                        break;

                    case OperationStatus.InvalidPassword:
                        errorMessage.Content = "The password is incorrect";
                        break;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void ShowPasswordButton_Click(object sender, RoutedEventArgs e)
        {
            //Toggle the password visible flag
            passwordIsVisible = !passwordIsVisible;

            if (passwordIsVisible)
            {
                PassBox.Visibility     = Visibility.Hidden;
                PassTextBox.Visibility = Visibility.Visible;
                PassTextBox.Focus();
                PassTextBox.Select(PassTextBox.Text.Length, 0);
            }
            else
            {
                PassBox.Visibility     = Visibility.Visible;
                PassTextBox.Visibility = Visibility.Hidden;
                PassBox.Focus();
            }
        }
        private void ButtonSend_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
            case Keys.Up:
                PassTextBox.Text   = String.Empty;
                e.SuppressKeyPress = true;
                PassTextBox.Focus();
                break;

            case Keys.Enter:
            case Keys.Down:
                if (LabelUserText.Text.Length > 3 && PassTextBox.Text.Length > 3)
                {
                    try
                    {
                        if (bool.Parse(Config.GetParametr("SaveLastLogin")))
                        {
                            Config.Set("SETTINGS", "LastLogin", LabelUserText.Text);
                        }
                    }
                    catch { }

                    ButtonSend.Enabled = false;

                    StartStatus();
                }
                else
                {
                    ButtonSend.ForeColor = Color.Red;
                }
                break;

            case Keys.Escape:
                PassTextBox.Text   = String.Empty;
                e.SuppressKeyPress = true;
                PassTextBox.Focus();
                break;
            }
        }
        private void LabelUserText_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
            case Keys.Enter:
            case Keys.Down:
                if (LabelUserText.Text.Length > 3)
                {
                    e.SuppressKeyPress = true;
                    PassTextBox.Focus();
                }
                else
                {
                    BackPanelUserText.BackColor = Color.Red;
                }
                break;

            case Keys.Escape:
                Application.Exit();
                break;
            }
        }
Ejemplo n.º 7
0
        private void RegisterClicked(object sender, RoutedEventArgs e)
        {
            logger.Info("RegisterClicked");

            if (firstNameTextBox.Text.Length == 0)
            {
                errorMessage.Content = "Enter first name.";
                firstNameTextBox.Focus();
            }
            else if (lastNameTextBox.Text.Length == 0)
            {
                errorMessage.Content = "Enter last name.";
                lastNameTextBox.Focus();
            }
            else if (nickNameTextBox.Text.Length == 0)
            {
                errorMessage.Content = "Enter nick name.";
                nickNameTextBox.Focus();
            }
            else if (emailAddrTextBox.Text.Length == 0)
            {
                errorMessage.Content = "Enter email.";
                emailAddrTextBox.Focus();
            }
            else if (!Regex.IsMatch(emailAddrTextBox.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
            {
                errorMessage.Content = "Enter a valid email.";
                emailAddrTextBox.Select(0, emailAddrTextBox.Text.Length);
                emailAddrTextBox.Focus();
            }
            else if (PassTextBox.Password.Length == 0)
            {
                errorMessage.Content = "Enter password.";
                PassTextBox.Focus();
            }
            else if (confirmPassTextBox.Password.Length == 0)
            {
                errorMessage.Content = "Enter Confirm password.";
                confirmPassLabel.Focus();
            }
            else if (PassTextBox.Password != confirmPassTextBox.Password)
            {
                errorMessage.Content = "Confirm password must be same as password.";
                confirmPassTextBox.Focus();
            }
            else
            {
                UserInformationData userData = new UserInformationData();
                userData.FirstName    = firstNameTextBox.Text;
                userData.LastName     = lastNameTextBox.Text;
                userData.NickName     = nickNameTextBox.Text;
                userData.EmailAddress = emailAddrTextBox.Text;
                userData.Password     = PassTextBox.Password;

                RegistrationResult result = service.UserRegistration(userData);

                if (result.Status == OperationStatus.Success)
                {
                    BackToLogin();
                }
                else
                {
                    MessageBox.Show("Registration Failed: " + result.Message);
                }
            }
        }
        private void AddEditButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (isChange)
                {
                    if ((PassTextBox.Text == "" || PassTextBox.Text == " ") && (ConfPassTextBox.Text == "" || ConfPassTextBox.Text == " ") && (LoginTextBox.Text != "" || LoginTextBox.Text != " "))
                    {
                        string       Command  = "Update Пользователи SET Имя_Пользователя=@login Where Имя_Пользователя=@oldLogin";
                        SqlParameter newLogin = new SqlParameter("login", LoginTextBox.Text);
                        SqlParameter oldLogin = new SqlParameter("oldLogin", Login);
                        StaticProcesser.ExecuteCommand(Command, newLogin, oldLogin);
                        this.Dispose();
                    }
                    else
                    {
                        if (PassTextBox.Text == ConfPassTextBox.Text && LoginTextBox.Text != "" && LoginTextBox.Text != " ")
                        {
                            string       newhashedPass = StaticProcesser.ComputeHash(PassTextBox.Text, new MD5CryptoServiceProvider());
                            SqlParameter newLogin      = new SqlParameter("login", LoginTextBox.Text);
                            SqlParameter newHashedPass = new SqlParameter("newHashedPass", newhashedPass);
                            SqlParameter oldLogin      = new SqlParameter("oldLogin", Login);
                            string       Command       = "Update Пользователи SET Имя_Пользователя=@login, Пароль=@newHashedPass Where Имя_Пользователя=@oldLogin";
                            StaticProcesser.ExecuteCommand(Command, newLogin, newHashedPass, oldLogin);
                            this.Dispose();
                        }
                    }
                }
                else
                {
                    if ((PassTextBox.Text == "" || PassTextBox.Text == " ") && (ConfPassTextBox.Text == "" || ConfPassTextBox.Text == " ") && (LoginTextBox.Text == "" || LoginTextBox.Text == " "))
                    {
                        MessageBox.Show("Заполните все поля!");
                        LoginTextBox.Focus();
                    }
                    else
                    {
                        if (PassTextBox.Text == ConfPassTextBox.Text)
                        {
                            string       newhashedPass = StaticProcesser.ComputeHash(PassTextBox.Text, new MD5CryptoServiceProvider());
                            SqlParameter newLogin      = new SqlParameter("login", LoginTextBox.Text);
                            SqlParameter newHashedPass = new SqlParameter("newHashedPass", newhashedPass);

                            string Command = "Insert INTO Пользователи (Имя_Пользователя,Пароль) VALUES (@login,@newHashedPass)";
                            StaticProcesser.ExecuteCommand(Command, newLogin, newHashedPass);
                            this.Dispose();
                        }
                        else
                        {
                            PassTextBox.Clear();
                            ConfPassTextBox.Clear();
                            PassTextBox.Focus();
                            MessageBox.Show("Пароли не совпадают!");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                StaticHelper.ErrorNotifier(ex);
            }
        }