Esempio n. 1
0
        private void ChangePasswordButton_Click(object sender, EventArgs e)
        {
            SqlConnection conn    = DBUtils.GetDBConnection();
            bool          success = false;

            try
            {
                if (validPassword == true)
                {
                    conn.Open();
                    string     command    = ("select *  from [dbo].[User] where [name]='" + NameBox.Text + "'and [password]='" + PreviousPasswordBox.Text + "';");
                    SqlCommand sqlCommand = new SqlCommand(command, conn);
                    using (var dataReader = sqlCommand.ExecuteReader())
                    {
                        success = dataReader.Read();
                    }
                    if (success)
                    {
                        if (NewPasswordBox.Text == NewPasswordRepeatBox.Text)
                        {
                            string     passwordCommand    = ("UPDATE [dbo].[User] SET password='******', dateofchange = '" + DateTime.Today.ToShortDateString() + "'where [name]='" + NameBox.Text + "'and [password]='" + PreviousPasswordBox.Text + "';");
                            SqlCommand passwordSqlCommand = new SqlCommand(passwordCommand, conn);
                            passwordSqlCommand.ExecuteNonQuery();
                            MessageBox.Show("Смена успешна");
                            this.Close();
                            Autorisation autorisation = new Autorisation();
                            autorisation.Show();
                        }
                        else if (NewPasswordBox.Text != NewPasswordRepeatBox.Text)
                        {
                            MessageBox.Show("Пароли не совпадают");
                            NewPasswordRepeatBox.BackColor = Color.Red;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Неверный логин или пароль");
                    }
                }
                else
                {
                    MessageBox.Show("Ваш новый пароль не соответствует требованиям");
                    NewPasswordBox.BackColor = Color.Red;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
            finally
            {
                conn.Close();
            }
        }
Esempio n. 2
0
        private void RegistrationButt_Click(object sender, EventArgs e)
        {
            if (validPassword == false)
            {
                MessageBox.Show("Ваш пароль не соответствует требованиям");
            }
            if (validPassLength != true)
            {
                MessageBox.Show("Длина пароля недостаточна");
            }
            if (validDigitPass != true)
            {
                MessageBox.Show("В пароле нет цифры");
            }
            if (validHighLetterPass != true)
            {
                MessageBox.Show("Нужна буква с верхним регистром");
            }
            if (validSpecSymbolsPass != true)
            {
                MessageBox.Show("Нужен один из спецсимволов: s% # $ & @");
            }
            if (validEmail == false)
            {
                MessageBox.Show("Ваша электронная мочта не соответствует требованиям");
            }
            SqlConnection conn = DBUtils.GetDBConnection();

            try
            {
                if (validPassword == true)
                {
                    if (validEmail == true)
                    {
                        conn.Open();
                        string     command    = ("INSERT INTO[dbo].[User]([name],[password],[email]) values('" + NameBox.Text + "','" + PasswordBox.Text + "','" + EmailBox.Text + "');");
                        SqlCommand sqlCommand = new SqlCommand(command, conn);
                        sqlCommand.ExecuteNonQuery();
                        MessageBox.Show("Произошло регистрирование");
                        this.Close();
                        Autorisation autorisation = new Autorisation();
                        autorisation.Show();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
            finally
            {
                conn.Close();
            }
        }