using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using PasswordCheckDll; namespace СУБД_Швейная_фабрика { public partial class FormRegistration : Form { public FormRegistration() { InitializeComponent(); } public string StrCon = @"Data Source=213.155.192.79,3002;Initial Catalog=FabrikaLDA;User ID=u21liseenko;Password=bfg2"; private void cbxPassword_CheckedChanged(object sender, EventArgs e) { tbxPas.UseSystemPasswordChar = !tbxPas.UseSystemPasswordChar; tbxPasRepeat.UseSystemPasswordChar = !tbxPasRepeat.UseSystemPasswordChar; } private void btnReg_Click(object sender, EventArgs e) { if (tbxLogin.Text == "" || tbxPas.Text == "" || tbxName.Text == "" || tbxFam.Text == "" || !tbxPhone.MaskFull || tbxOtch.Text == "") { MessageBox.Show("Заполните все поля", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (tbxPas.Text != tbxPasRepeat.Text) { MessageBox.Show("Пароли не совпадают", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!PasswordCheckClass.PasswordCheck(tbxPas.Text)) { MessageBox.Show(@"Пароли не соответствует требования: • длина пароля – минимум 6 символов; • обязательно и строчные и прописные символы; • цифр должно быть не более половины от всех символов пароля; • должен содержать минимум 1 символ из набора: ! @ # $ % ^. ","Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } SqlConnection con = new SqlConnection(StrCon); SqlCommand cmd = new SqlCommand($"select Login from Users where Login = '{tbxLogin.Text}'", con); con.Open(); SqlDataReader res = cmd.ExecuteReader(); res.Read(); if (res.HasRows) { MessageBox.Show("Данный логин уже занят", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }else { res.Close(); SqlCommand cmdInsert = new SqlCommand($@"Insert into Users(Login,Password,Role,Fam,Name,Otch,Phone) Values('{tbxLogin.Text}','{tbxPas.Text}',3,'{tbxFam.Text}','{tbxName.Text}','{tbxOtch.Text}','{tbxPhone.Text}')", con); cmdInsert.ExecuteNonQuery(); MessageBox.Show("Регистрация прошла успешно!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information); } con.Close(); this.Close(); } } }