private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            var login    = tbLogin.Text;
            var password = tbPassword.Password;

            var hashedPassword = new StringBuilder();

            using (MD5 md5Provider = new MD5CryptoServiceProvider())
            {
                byte[] bytes = md5Provider.ComputeHash(Encoding.ASCII.GetBytes(password));

                for (int i = 0; i < bytes.Length; i++)
                {
                    hashedPassword.Append(bytes[i].ToString("x2"));
                }
            }

            var adminsRep = new SqlAdministratorRepository(connection);

            var admin = adminsRep.GetAdministratorByLogin(login, hashedPassword.ToString());

            if (admin != null)
            {
                CurrentAdministrator.SignIn(admin);

                (new MainWindow()).Show();
                this.Close();
            }
            else
            {
                MessageBox.Show("Incorrect username or password.", "Authorization error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            var administratorRepository = new SqlAdministratorRepository(frmGymManager.connectionString);
            var admin = new Administrator();

            if (dgvAddAdmin.CurrentRow.Cells[0].Value != null && dgvAddAdmin.CurrentRow.Cells[1].Value != null &&
                dgvAddAdmin.CurrentRow.Cells[2].Value != null && dgvAddAdmin.CurrentRow.Cells[3].Value != null)
            {
                admin.Name     = dgvAddAdmin.CurrentRow.Cells[0].Value.ToString();
                admin.Surname  = dgvAddAdmin.CurrentRow.Cells[1].Value.ToString();
                admin.Login    = dgvAddAdmin.CurrentRow.Cells[2].Value.ToString();
                admin.Password = Encrypt.GetHash(dgvAddAdmin.CurrentRow.Cells[3].Value.ToString());

                if (administratorRepository.AddNewAdministrator(admin) > 0)
                {
                    MessageBox.Show("Successfull operation", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Try Again", "Allert", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                MessageBox.Show("Enter data!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#3
0
 public LoginForm()
 {
     _administratorRepository = new SqlAdministratorRepository(_connectionString);
     InitializeComponent();
 }