private void button_DangNhap_Click(object sender, EventArgs e) { string passMD5 = txtMatKhau.Text; passMD5 = getMD5(txtMatKhau.Text); try { SqlConnection kn = knoi(); string a = txtMatKhau.Text; string b = txtNhapLaiMatKhau.Text; if (a == b) { string str = "SELECT * FROM DangNhap WHERE TaiKhoan = N'" + txtTenDangKy.Text + "' "; if (txtTenDangKy.Text.Trim() == "") { MessageBox.Show("Bạn chưa nhập tên người dùng !", "Đăng Ký", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (txtMatKhau.Text.Trim() == "") { MessageBox.Show("Bạn chưa nhập mật khẩu!", "Đăng Ký", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { DataTable ba = bang(str); int i = ba.Rows.Count; if (i > 0) { MessageBox.Show("Tên tài khoản đã được sử dụng, vui lòng sử dụng tên khác !", "Đăng Ký", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtTenDangKy.FindForm(); txtMatKhau.Text = ""; txtTenDangKy.Text = ""; txtNhapLaiMatKhau.Text = ""; } else { /* * string sql = "INSERT INTO DangNhap VALUES('" + txtTenDangKy.Text + "' ,'" + passMD5 + "',1) "; + + kn.Open(); + SqlCommand them = new SqlCommand(sql, kn); + them.ExecuteNonQuery(); + them.Dispose(); + */ dt.TaiKhoan_Insert(txtTenDangKy.Text, passMD5, "1"); if (MessageBox.Show("Đăng ký thành công, bạn có muốn đi tới đăng nhập?", "Đăng Ký", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Form_DangNhap dn = new Form_DangNhap(); dn.Show(); } else { txtTenDangKy.Text = ""; txtMatKhau.Text = ""; txtNhapLaiMatKhau.Text = ""; } kn.Close(); } } } else { MessageBox.Show("Mật khẩu bạn nhập không khớp! Vui lòng kiểm tra lại!", "Đăng Ký", MessageBoxButtons.OK, MessageBoxIcon.Error); txtTenDangKy.Text = ""; txtNhapLaiMatKhau.Text = ""; } kn.Close(); } catch (Exception) { MessageBox.Show("Thao Tác Không Thực Hiện Được. Vui Lòng Kiểm Tra Lại!", "Đăng Nhập", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button_DangNhap_Click_1(object sender, EventArgs e) { try { string passMD5 = getMD5(textBox_Pass.Text); string tentk = textBox_User.Text; string matkhau = textBox_Pass.Text; if (tentk == "") { MessageBox.Show("Bạn chưa nhập tên tài khoản", "Đăng nhập", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { if (matkhau == "") { MessageBox.Show("Bạn chưa nhập mật khẩu", "Đăng Nhập", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { string dangNhap = "SELECT * FROM DangNhap WHERE TaiKhoan = '" + textBox_User.Text + "' and MatKhau='" + passMD5 + " '"; DataTable dt = CSDL.bang(dangNhap); int i = dt.Rows.Count; if (sai > 0) { if (i > 0) { DataTable datadn = CSDL.bang(dangNhap); tk = int.Parse(datadn.Rows[0][2].ToString());//Lấy thông tin cấp độ tài khoản if (tk == 1) { MessageBox.Show("Quản trị viên " + "\"" + textBox_User.Text + "\"" + " đã đăng nhập", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); //this.Close(); } else if (tk == 2) { MessageBox.Show("Giáo viên " + "\"" + textBox_User.Text + "\"" + " đã đăng nhập", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (tk == 3) { MessageBox.Show("Sinh viên " + "\"" + textBox_User.Text + "\"" + " đã đăng nhập", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { tk = 0; } using (Form1 gd = new Form1()) { if (tk == 1 || tk == 2) { gd.getUsername = textBox_User.Text; } else { gd.getUsername2 = textBox_User.Text; } gd.ShowDialog(); this.Close(); } } else { tk = 0; sai = sai - 1; MessageBox.Show("Sai tên tài khoản hoặc mật khẩu! Bạn còn " + sai + " lần đăng nhập", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); this.textBox_User.Clear(); this.textBox_Pass.Clear(); this.textBox_User.Focus(); } } else { MessageBox.Show("Bạn đã hết lượt truy cập đăng nhập. Mời đăng nhập lại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); Form_DangNhap gd1 = new Form_DangNhap(); gd1.Show(); } } } } catch (Exception) { MessageBox.Show("Lỗi kết nối với máy chủ, vui lòng thử lại", "Lỗi kết nối", MessageBoxButtons.OK, MessageBoxIcon.Error); }; }