private void DangNhap() { try { if (txtUsername.Text == "") { MessageBox.Show("Chưa nhập username"); return; } if (txtPassword.Text == "") { MessageBox.Show("Chưa nhập password"); return; } NhanVienDTO nhanvienDTO = null; NhanVienBUS nhanvienBUS = new NhanVienBUS(); string username = txtUsername.Text; nhanvienDTO = nhanvienBUS.Search(username); byte[] plainTextBytes = ASCIIEncoding.ASCII.GetBytes(txtPassword.Text.ToString()); MD5CryptoServiceProvider myMD5 = new MD5CryptoServiceProvider(); byte[] byteHash = myMD5.ComputeHash(plainTextBytes); StringBuilder sOutput = new StringBuilder(byteHash.Length); for (int i = 0; i < byteHash.Length; i++) { sOutput.Append(byteHash[i].ToString("X2")); // X2 formats to hexadecimal } if (nhanvienDTO == null) { MessageBox.Show("Không tìm thấy nhân viên có username là : " + txtUsername.Text); return; } else { if (nhanvienDTO.Password == sOutput.ToString() && nhanvienDTO.Loai == 1) { //this.Visible = false; kiemTraDangNhap = true; gUserName = username; this.Close(); //frmQuanLySach frm = new frmQuanLySach(); //frmQuanLySanPham frm = new frmQuanLySanPham(); //frm.ShowDialog(); } else { if (nhanvienDTO.Password == sOutput.ToString() && nhanvienDTO.Loai == 2) { kiemTraDangNhap = true; gUserName = username; this.Close(); frmQuanTriVien frm = new frmQuanTriVien(); frm.ShowDialog(); } else { MessageBox.Show("Password không hợp lệ"); return; } } } } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }
private void btnDangNhap_Click(object sender, EventArgs e) { try { if (txtUsername.Text == "") { MessageBox.Show("Chưa nhập username"); return; } if (txtPassword.Text == "") { MessageBox.Show("Chưa nhập password"); return; } QuanThuDTO quanthuDTO = null; QuanThuBUS quanthuBUS = new QuanThuBUS(); string username = txtUsername.Text; quanthuDTO = quanthuBUS.Search(username); byte[] plainTextBytes = ASCIIEncoding.ASCII.GetBytes(txtPassword.Text.ToString()); MD5CryptoServiceProvider myMD5 = new MD5CryptoServiceProvider(); byte[] byteHash = myMD5.ComputeHash(plainTextBytes); StringBuilder sOutput = new StringBuilder(byteHash.Length); for (int i = 0; i < byteHash.Length; i++) { sOutput.Append(byteHash[i].ToString("X2")); // X2 formats to hexadecimal } if (quanthuDTO == null) { MessageBox.Show("Không tìm thấy quản thư có username là : " + txtUsername.Text); return; } else { if (quanthuDTO.Password == sOutput.ToString() && quanthuDTO.Loai == 1) { //this.Visible = false; kiemTraDangNhap = true; this.Close(); frmQuanLySach frm = new frmQuanLySach(); frm.ShowDialog(); } else { if (quanthuDTO.Password == sOutput.ToString() && quanthuDTO.Loai == 2) { kiemTraDangNhap = true; frmQuanTriVien frm = new frmQuanTriVien(); frm.ShowDialog(); } else { MessageBox.Show("Password không hợp lệ"); return; } } } } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }