public ActionResult ValidarUsuario(string sUsuario, string sPassword) { bool blResult = false; string nombres = string.Empty; int cod = 0; try { blResult = new BLLogin().ValidarUsuario(sUsuario, sPassword, ref nombres, ref cod); if (blResult) { Session["Usuario"] = cod; Session["NombreUsuario"] = nombres; return(Json(new { success = true, responseText = "OK" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, responseText = "Usuario o clave incorrecta" }, JsonRequestBehavior.AllowGet)); } } catch (TimeoutException exx) { return(Json(new { success = false, responseText = exx.Message }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { success = false, responseText = ConfigurationManager.AppSettings["strErrorGeneral"] }, JsonRequestBehavior.AllowGet)); } }
public IHttpActionResult Authenticate([FromBody] UserLogin login) { IHttpActionResult response; HttpResponseMessage httpResponse = null; if (login != null) { login = new BLLogin().Login(login.UserName, EncryptUtil.MD5Hash(login.Password)); } if (login != null) { // Tài khoản mật khẩu hợp lệ thì Tạo Token string token = CreateToken(login.UserName); // return Ok<string>(token); httpResponse = Request.CreateResponse(HttpStatusCode.OK, new ServiceResult(true, null, token, null)); } else { // Nếu không hợp lệ thì trả về lỗi httpResponse = Request.CreateResponse(HttpStatusCode.Unauthorized, new ServiceResult(false, ErrorCode.InvalidPassword)); } response = ResponseMessage(httpResponse); return(response); }
private void BtnLogin_Click(object sender, EventArgs e) { if (String.IsNullOrWhiteSpace(txtUserName.Text)) { MessageBox.Show("Utilizatorul nu este completat", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (String.IsNullOrWhiteSpace(txtPassword.Text)) { MessageBox.Show("Parola nu este completata", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } BLLogin bl = new BLLogin(); UserModel user = bl.CheckUser(txtUserName.Text, txtPassword.Text, out bool status); if (status) { MainMenuForm mainMenu = new MainMenuForm(); mainMenu.UserId = user.UserId; mainMenu.Show(); this.Hide(); mainMenu.FormClosed += MainMenu_FormClosed; } else { MessageBox.Show("Utilizator sau parola incorecta", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnSave_Click(object sender, EventArgs e) { // Mở kết nối // Thêm dữ liệu if (Add) { try { // Thực hiện lệnh BLLogin blLogin = new BLLogin(); blLogin.ThemAc(txtTaikhoan.Text, txtMK.Text, txtHoTen.Text, txtGT.Text, mskPhone.Text, txtEmail.Text); // Load lại dữ liệu trên DataGridView LoadData(); // Thông báo MessageBox.Show("Đã thêm xong!"); } catch { MessageBox.Show("Không thêm được. Lỗi rồi!"); } } else { // Thực hiện lệnh BLLogin blLogin = new BLLogin(); blLogin.CapNhatAc(txtTaikhoan.Text, txtMK.Text, txtHoTen.Text, txtGT.Text, mskPhone.Text, txtEmail.Text); // Load lại dữ liệu trên DataGridView LoadData(); // Thông báo MessageBox.Show("Đã sửa xong!"); } // Đóng kết nối }
protected void Page_Load(object sender, EventArgs e) { try { b = new BLLogin(); } catch (Exception ex) { throw new ArgumentException(ex.Message); } }
protected void Page_Load(object sender, EventArgs e) { Page.UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.None; if (new ControlSeguridad().validarNutri() == true) { Response.Redirect("~/InicioSesion.aspx"); } BLLogin usua = (BLLogin)Session["usuario"]; lbUsuario.Text = usua.correo; }
private void btnChange_Click(object sender, EventArgs e) { BLLogin lg = new BLLogin(); if (lg.ChangePassAccount(user, txtMKcu.Text, txtMKmoi.Text, txtConfimMk.Text, quyen)) { MessageBox.Show("Cập nhật mật khẩu thành công"); } else { MessageBox.Show("Cập nhật mật khẩu thất bại"); } }
public object Get([FromBody] UserLogin login) { ServiceResult result = new ServiceResult(); if (login != null) { login = new BLLogin().Login(login.UserName, EncryptUtil.MD5Hash(login.Password)); } if (login != null) { result.Data = login; } else { result.Success = false; result.ErrorCode = ErrorCode.InvalidPassword; } return(result); }
protected void btnCambiar_Click(object sender, EventArgs e) { BLLogin usuar = (BLLogin)Session["usuario"]; string correo = usuar.correo; string contrActual = usuar.contras; string contras = ""; contras = txtcontraAct.Text; string contraNueva = txtContra.Text; if (usuarioLogin.buscarUsuario(correo, contras) == null) { Page.ClientScript.RegisterStartupScript(this.GetType(), "mensajeError", "mensajeError('error', 'Datos incorrectos', 'Contraseña actual incorrecta')", true); return; } else { usuarioLogin.ModifUsuario(correo, contraNueva); Page.ClientScript.RegisterStartupScript(this.GetType(), "mensajeError", "mensajeError('success', 'Bien', 'Contraseña modificada correctamente')", true); } }
private void BtnCreateUser_Click(object sender, EventArgs e) { if (String.IsNullOrWhiteSpace(txtUserName.Text)) { MessageBox.Show("Utilizator necompletat", "EROARE", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (String.IsNullOrWhiteSpace(txtPassword.Text)) { MessageBox.Show("Parola necompletata", "EROARE", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string userName = txtUserName.Text; string password = txtPassword.Text; BLLogin blLogin = new BLLogin(); UserModel user = new UserModel(); blLogin.InsertUser(userName, password, out bool status, out string error); if (status)//userul nu s-a inserat { MessageBox.Show(error, "EROARE", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else//userul s-a inserat { MessageBox.Show(error, "SUCCES!", MessageBoxButtons.OK, MessageBoxIcon.Error); MainMenuForm mainMenu = new MainMenuForm(); mainMenu.Show(); this.Hide(); mainMenu.FormClosed += MainMenu_FormClosed; return; } }
private void BtnLogin_Click(object sender, EventArgs e) { if (String.IsNullOrWhiteSpace(txtUserName.Text)) { MessageBox.Show("Utilizator necompletat", "EROARE", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (String.IsNullOrWhiteSpace(txtPassword.Text)) { MessageBox.Show("Parola necompletata", "EROARE", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string userName = txtUserName.Text; string password = txtPassword.Text; BLLogin blLogin = new BLLogin(); UserModel user = new UserModel(); user = blLogin.CheckUser(userName, password, out bool status, out string errorMessage); if (status)//s-a gasit userul { MainMenuForm mainMenu = new MainMenuForm(); mainMenu.Show(); this.Hide(); mainMenu.FormClosed += MainMenu_FormClosed; UserId = user.UserId; } else { MessageBox.Show(errorMessage, "EROARE", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
private void btnLogin_Click(object sender, EventArgs e) { if (String.IsNullOrWhiteSpace(txtUser.Text)) { MessageBox.Show("Numele de utilizator nu a fost completat.", "Atentie", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (String.IsNullOrWhiteSpace(txtPass.Text)) { MessageBox.Show("Parola nu a fost completata.", "Atentie", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } BLLogin bl = new BLLogin(); UserModel userModel = bl.CheckUser(txtUser.Text, txtPass.Text, out int status, out Boolean isActive); if (status == 2) { if (isActive == true) { if (userModel.UserTypeId == 1) { MenuForm menuForm = new MenuForm(userModel.UserInfoId, userModel.UserTypeId); menuForm.Show(); this.Hide(); menuForm.FormClosed += Menu_FormClosed; } else if (userModel.UserTypeId == 0) { MenuFormTeachers menuFormTeachers = new MenuFormTeachers(userModel.UserInfoId, userModel.UserTypeId); menuFormTeachers.Show(); this.Hide(); menuFormTeachers.FormClosed += Menu_FormClosed; } else if (userModel.UserTypeId == 2) { MenuFormExternals menuFormExternals = new MenuFormExternals(userModel.UserInfoId, userModel.UserTypeId); menuFormExternals.Show(); this.Hide(); menuFormExternals.FormClosed += Menu_FormClosed; } else if (userModel.UserTypeId == 3) { MenuFormAdmin menuFormAdmin = new MenuFormAdmin(); menuFormAdmin.Show(); this.Hide(); menuFormAdmin.FormClosed += Menu_FormClosed; } } else { MessageBox.Show("Utilizatorul nu este activ.", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } else { if (status == 0) { MessageBox.Show("Parola introdusa este incorecta", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error); //txtUser.Clear(); txtPass.Clear(); return; } else { MessageBox.Show("Numele de utilizator introdus este gresit", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error); txtUser.Clear(); //txtPass.Clear(); return; } } }
public static string UserLogged = ""; //For tracking the User who logged. private void btnLogin_Click(object sender, RoutedEventArgs e) //When you hit the Login button.... { MD5 md5Hash = MD5.Create(); //Initial MD5 hash code for encrypt the password. if (Properties.Settings.Default.checkerAuto == false) //Check if the "Remember auto login" is unchecked last session. { string MD5Password = GetMd5Hash(md5Hash, txtPassword.Password); //Hash the password is typed by User to MD5Password. user.MD5Password = MD5Password; //This MD5Password will be saved to Database. user.Username = txtUsername.Text; } else { user.MD5Password = Properties.Settings.Default.rePassword; //"Remember auto login" is checked so it loads MD5Password from Properties.Settings user.Username = Properties.Settings.Default.reUsername; //Same as Username. } bool valid = BLLogin.TryToLogin(user.Username, user.MD5Password); //Compare the username & hashed password to Database. bool IsUsernameValid = BLLogin.IfUsernameValid(user.Username); //Check if the username exist. if (LoginCount < 4) { if (valid) //If Username & Hashed Password valid -> Access to main window. { LoginSuccess = true; L3.UserID = user.Username; Close(); } else if (IsUsernameValid) //Else check the Username only. If the Username is correct, highlight the Wrong Password notification. { lbWrongUsernamePassword.Visibility = Visibility.Hidden; LoginSuccess = false; lbPassword.Foreground = new SolidColorBrush(Colors.Red); txtPassword.BorderBrush = new SolidColorBrush(Colors.Red); lbWrongPassword.Visibility = Visibility.Visible; LoginCount++; } else //When both Username & Password are wrong. Show the Wrong notification. { lbWrongPassword.Visibility = Visibility.Hidden; LoginSuccess = false; lbUsername.Foreground = new SolidColorBrush(Colors.Red); lbWrongUsernamePassword.Visibility = Visibility.Visible; txtUsername.BorderBrush = new SolidColorBrush(Colors.Red); LoginCount++; } } else //STOP IT YOUR ACCESS IS DENIED. YOU'VE TYPED INVALID INFORMATION FOR 5 TIMES. { LoginCount = 0; MessageBox.Show("Bạn đã nhập sai quá số lần quy định.\n Màn hình đăng nhập sẽ bị khóa trong 5 phút!"); btnLogin.IsEnabled = false; //Disable Login button. System.Timers.Timer timer = new System.Timers.Timer(); //Just call the timer to delay 5 minutes. timer.Interval = 300000; //Bad security. Prevent brute-force temporarily =]]z timer.Elapsed += new ElapsedEventHandler(EnableBtn); timer.Enabled = true; } /////////////////////The section below do saving if "Remember login information" or "Remember auto login" is checked. if (ceRememberLogin.IsChecked == true && ceAutoLogin.IsChecked == false) { Properties.Settings.Default.checkerUser = true; Properties.Settings.Default.checkerAuto = false; Properties.Settings.Default.reUsername = user.Username; Properties.Settings.Default.Save(); } else if (ceRememberLogin.IsChecked == false || ceAutoLogin.IsChecked == false) { Properties.Settings.Default.checkerUser = false; Properties.Settings.Default.checkerAuto = false; Properties.Settings.Default.reUsername = ""; Properties.Settings.Default.rePassword = ""; Properties.Settings.Default.Save(); } else if (ceAutoLogin.IsChecked == true) { Properties.Settings.Default.checkerAuto = true; Properties.Settings.Default.reUsername = user.Username; Properties.Settings.Default.rePassword = user.MD5Password; Properties.Settings.Default.Save(); } ////////////////////End of saving section. }