private void btnThem1NV_Click(object sender, EventArgs e) { // check điều kiện if (txtMatKhauNV.Text == "" || txtTaiKhoanNV.Text == "") { MessageBox.Show("Hãy nhập lại thông tin", "Nhập thông tin", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Adminn ad = new Adminn(); ad.MatKhau = txtMatKhauNV.Text; ad.ChucVu = cboCongViec.SelectedItem.ToString(); // thêm tk if (btnThem1NV.Text == "Thêm") { ad.TaiKhoan = txtTaiKhoanNV.Text; } // sửa thông tin else { string tk = dgvHienThiThongTinNV.SelectedRows[0].Cells["TaiKhoan"].Value.ToString(); ad.TaiKhoan = tk; } // xử lý thêm/sửa DialogResult dr = MessageBox.Show("Xác nhận thông tin ", " Tài Khoản", MessageBoxButtons.OKCancel); if (dr == DialogResult.OK) { BLL_Admin.Instance.ExecuteDB(ad); ShowDgv(cboHienThiTheo.SelectedItem.ToString()); } } }
public Adminn AuthenticateUser(string username, string password) { Adminn adminn = null; // user token to build // we need to hash the password first var passwordHash = HashSha256(password); try { // we need to pass the username and passwordhash // to the data access method - if we get back a 1, the user is // validated, anything else is unacceptable var validationResult = AdminnAccessor.VerifyUsernameAndPassword(username, passwordHash); if (validationResult == 1) // user is validated { // need to get the employee object and roles // to build the user object // first, get the employee adminn = AdminnAccessor.RetrieveAdminnByUsername(username); // next, get the employee's roles //var roles = AdminnAccessor.RetrieveRolesByEmployeeID(employee.EmployeeID); // bool passwordMustBeChanged = false; // here's some code to prevent the user from using the app without // changing his or her password first /* if(password=="newuser") * { * passwordMustBeChanged = true; * roles.Clear(); // clear the user's roles so the app can't be used * roles.Add(new Role() { RoleID = "New User" }); * } * * // and create the user token * user = new User(employee, roles, passwordMustBeChanged); */ } else // user was not validated { // we can throw an exception here. throw new ApplicationException("Login failed. Bad username (email address) or password"); } } catch (ApplicationException) // rethrow the applicaton exception { throw; } catch (Exception ex) // wrap and throw other types of exception { throw new ApplicationException("There was a problem connecting to the server.", ex); } return(adminn); }
public void DoiMatKhau(string tk, string mkmoi) { QLTTDayThem db = new QLTTDayThem(); Adminn a = db.Adminns.Find(tk); a.MatKhau = mkmoi; db.SaveChanges(); }
public static Tai_khoan layThongTinTaiKhoan(string taiKhoan) { using (var qlttn = new QLTTNDataContext()) { var thongTin = qlttn.NGUOIDUNGs.Where(nd => nd.TaiKhoan.Equals(taiKhoan)) .Select(nd => new { nd }).Single(); if (thongTin.nd.MaPhanQuyen.Equals("AD ")) { Adminn ad = new Adminn(); ad.Ho_Ten = thongTin.nd.HoTen; ad.Ngay_Sinh = thongTin.nd.NgaySinh.Value; ad.Tai_Khoan = thongTin.nd.TaiKhoan; ad.CMND_TCC = thongTin.nd.CMND_TCC; return(ad); } else if (thongTin.nd.MaPhanQuyen.Equals("GV ")) { var thongTinn = qlttn.NGUOIDUNGs .Join(qlttn.KHOIs, nd => nd.MaKhoi, k => k.MaKhoi, (nd, k) => new { nd, k.TenKhoi }) .Where(nd => nd.nd.TaiKhoan.Equals(taiKhoan)) .Select(nd => new { nd }).Single(); Giao_Vienn gv = new Giao_Vienn(); gv.Tai_Khoan = thongTinn.nd.nd.TaiKhoan; gv.Ho_Ten = thongTinn.nd.nd.HoTen; gv.CMND_TCC = thongTinn.nd.nd.CMND_TCC; gv.Ngay_Sinh = thongTinn.nd.nd.NgaySinh.Value; gv.SDT = thongTinn.nd.nd.SoDienThoai; gv.Email = thongTinn.nd.nd.Email; gv.Khoi = thongTinn.nd.TenKhoi; return(gv); } else { var thongTinn = qlttn.NGUOIDUNGs .Join(qlttn.LOPHOCs, nd => nd.MaLop, lh => lh.MaLop, (nd, lh) => new { nd, lh }) .Join(qlttn.KHOIs, nd => nd.lh.MaKhoi, k => k.MaKhoi, (nd, k) => new { nd, k.TenKhoi }) .Where(nd => nd.nd.nd.TaiKhoan.Equals(taiKhoan)) .Select(nd => new { nd }).Single(); Hoc_Sinhh hs = new Hoc_Sinhh(); hs.Tai_Khoan = thongTinn.nd.nd.nd.TaiKhoan; hs.Ho_Ten = thongTinn.nd.nd.nd.HoTen; hs.CMND_TCC = thongTinn.nd.nd.nd.CMND_TCC; hs.Ngay_Sinh = thongTinn.nd.nd.nd.NgaySinh.Value; hs.SDT = thongTinn.nd.nd.nd.SoDienThoai; hs.Email = thongTinn.nd.nd.nd.Email; hs.Khoi = thongTinn.nd.TenKhoi; hs.Lop = thongTinn.nd.nd.lh.TenLop; return(hs); } } }
// GET: Index public ActionResult Index() { var model = new Adminn() { Admin = db.Admins.ToList().FirstOrDefault() }; return(View(model)); }
public MainForm(Adminn s) { InitializeComponent(); ad = s; setQuyen(ad.ChucVu); panelleftmenu = new Panel(); panelleftmenu.Size = new Size(5, 49); //panelleftmenu.BackColor = Color.Green; pnMenu.Controls.Add(panelleftmenu); }
public ActionResult Verificacion(Adminn aa) { if (ModelState.IsValid) { return(RedirectToAction("Ok")); } else { return(View(aa)); } }
public void XoaTK(List <string> tk) { QLTTDayThem db = new QLTTDayThem(); for (int i = 0; i < tk.Count; i++) { Adminn ad = db.Adminns.Find(tk[i]); db.Adminns.Remove(ad); db.SaveChanges(); } }
public bool CheckTK(string tk) { QLTTDayThem db = new QLTTDayThem(); Adminn ad = db.Adminns.Find(tk); if (ad != null) { return(true); } else { return(false); } }
public Adminn CheckTK(string tk, string pw) { QLTTDayThem db = new QLTTDayThem(); Adminn a = db.Adminns.Find(tk); if (a != null && a.MatKhau == pw) { return(a); } else { return(null); } }
private void logout() { _adminn = null; // do anything else we need to do to clear the screen, to be done later // reenable the login controls txtPassword.Visibility = Visibility.Visible; txtUsername.Visibility = Visibility.Visible; lblPassword.Visibility = Visibility.Visible; lblUsername.Visibility = Visibility.Visible; btnLogin.Content = "Log In"; clearLogin(); statusMain.Items[0] = "You are not logged in."; hideAllTabs(); }
public void ExecuteDB(Adminn a) { QLTTDayThem db = new QLTTDayThem(); Adminn ad = db.Adminns.Find(a.TaiKhoan); if (ad != null) { ad.MatKhau = a.MatKhau; ad.ChucVu = a.ChucVu; db.SaveChanges(); } else { db.Adminns.Add(a); db.SaveChanges(); } }
public ActionResult Verificacion(string Rut, string Contraseña) { Administradores admm = db.Administradores.Where(x => x.rut == Rut && x.contraseña == Contraseña) .FirstOrDefault(); if (admm != null) { Adminn aaa = new Adminn(); aaa.Rut = admm.rut; aaa.Contraseña = admm.contraseña; Session["Adminn"] = aaa.Rut; return(Redirect("/Mantenedor/Index")); } else { ViewBag.error = "Usuario o clave Incorrectos"; return(Redirect("../Menu/Menu")); } }
public async Task <IActionResult> GirisYAPAsync(Adminn p) { var bilgiler = c.adminns.FirstOrDefault(x => x.kullanici == p.kullanici && x.sifre == p.sifre); if (bilgiler != null) { var claims = new List <Claim> { new Claim(ClaimTypes.Name, p.kullanici) }; var Useridentity = new ClaimsIdentity(claims, "Logincotroller"); ClaimsPrincipal principal = new ClaimsPrincipal(Useridentity); await HttpContext.SignInAsync(principal); return(RedirectToAction("Index", "Personel")); } return(View()); }
private void btnSua_Click(object sender, EventArgs e) { btnThem1NV.Text = "Sửa"; pnThongTin.Visible = true; pnChucNang.Visible = false; if (dgvHienThiThongTinNV.SelectedRows.Count == 1) { string tk = dgvHienThiThongTinNV.SelectedRows[0].Cells["TaiKhoan"].Value.ToString(); Adminn ad = BLL_Admin.Instance.GetADbyTK(tk); txtTaiKhoanNV.Text = ad.TaiKhoan; txtTaiKhoanNV.Enabled = false; txtMatKhauNV.Text = ad.MatKhau; cboCongViec.Text = ad.ChucVu; } else { MessageBox.Show("Chọn 1 row để sửa", "Sửa Tài Khoản", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void metroButton1_Click(object sender, EventArgs e) { try { if (validateentry()) { Adminn admin = new Adminn(); admin.Username = txtUsername.Text; admin.Password = txtPassword.Text; admin.VerifyLogin(); if (admin.Status == 1) { usersetings = new ClsUserSetting(txtUsername.Text); string successMessage = string.Format("Welcome" + " " + txtUsername.Text + " " + admin.facdeptid); MessageBox.Show((successMessage)); Form home = new Home(txtUsername.Text, admin.Usertype, admin.facdeptid); this.Hide(); home.Show(); } else { MessageBox.Show("Incorrect Username or Password", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } else { return; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void btnLogin_Click(object sender, RoutedEventArgs e) { /* MessageBox.Show("welcome", "Login successed!", * MessageBoxButton.OK, MessageBoxImage.Exclamation); * return;*/ if (_adminn != null) // this means someone is logged in, so log out! { logout(); return; } // accept the input var username = txtUsername.Text; var password = txtPassword.Password; // check for missing or invalid data if (username.Length < MIN_USERNAME_LENGTH || username.Length > MAX_USERNAME_LENGTH) { MessageBox.Show("Invalid Username", "Login Failed!", MessageBoxButton.OK, MessageBoxImage.Exclamation); clearLogin(); return; } if (password.Length <= MIN_PASSWORD_LENGTH) { MessageBox.Show("Invalid Password", "Login Failed!", MessageBoxButton.OK, MessageBoxImage.Exclamation); clearLogin(); return; } // normally, we would also include some logic here to test for // password complexity rules, usually against a regular expression. // That makes testing slow, during development, because passwords // that are complex are a pain in the neck. // before checking for the user token, we need to use a try block try { _adminn = _adminnManager.AuthenticateUser(username, password); /* if (_adminn.Roles.Count == 0) * { * // check for unauthorized user * _adminn = null; * * MessageBox.Show("You have not been assigned any roles. \nYou will be logged out. \nPlease see your supervisor.", * "Unauthorized Admin", MessageBoxButton.OK, * MessageBoxImage.Stop); * * clearLogin(); * * return; * }*/ // user is now logged in var message = "Welcome back, " + _adminn.FirstName + ". You are logged in as: "; /*foreach (var r in _adminn.Roles) * { * message += r.RoleID + " "; * }*/ //showUserTabs(); statusMain.Items[0] = message; clearLogin(); txtPassword.Visibility = Visibility.Hidden; txtUsername.Visibility = Visibility.Hidden; lblPassword.Visibility = Visibility.Hidden; lblUsername.Visibility = Visibility.Hidden; // we need to stop having the login button as default for hitting // the enter key when someone is logged in to prevent accidental logouts this.btnLogin.IsDefault = false; btnLogin.Content = "Log Out"; // check for expired password /* if (_adminn.PasswordMustBeChanged) * { * changePassword(); * }*/ } catch (Exception ex) // nowhere to throw an exception at the presentation layer { string message = ex.Message; if (ex.InnerException != null) { message += "\n\n" + ex.InnerException.Message; } MessageBox.Show(message, "Login Failed!", MessageBoxButton.OK, MessageBoxImage.Exclamation); clearLogin(); return; } }
public frmDoiMatKhau(Adminn s) { InitializeComponent(); ad = s; }
public frmTaiKhoan(Adminn s) { InitializeComponent(); ad = s; }
public static Adminn RetrieveAdminnByUsername(string username) { Adminn adminn = null; // connection first var conn = DBConnection.GetDBConnection(); // command text var cmdText = @"sp_retrieve_adminn_by_email"; // command var cmd = new SqlCommand(cmdText, conn); // command type cmd.CommandType = CommandType.StoredProcedure; // parameters cmd.Parameters.Add("@AdminnEmail", SqlDbType.NVarChar, 100); // parameeter values cmd.Parameters["@AdminnEmail"].Value = username; // try-catch to execute the command try { // open the connection conn.Open(); // execute the command var reader = cmd.ExecuteReader(); // process the results if (reader.HasRows) { reader.Read(); // reads the next line in the result // create a new employee object adminn = new Adminn() { // SELECT [EmployeeID], [FirstName], [LastName], [PhoneNumber], [Email], [Active] AdminnID = reader.GetString(0), FirstName = reader.GetString(1), LastName = reader.GetString(2), PhoneNumber = reader.GetString(3), AdminnEmail = reader.GetString(4), Active = reader.GetBoolean(5) }; if (adminn.Active != true) { throw new ApplicationException("Not an active employee."); } } else { throw new ApplicationException("Employee record not found!"); } } catch (Exception) { throw; } finally { conn.Close(); } return(adminn); }