private void btnSavePassword_Click(object sender, EventArgs e) { if (txtOldPassword.Text == "" || string.IsNullOrEmpty(txtOldPassword.Text)) { if (txtOldPassword.Text != "") { lblErroOldPassword.Visible = false; } lblErroOldPassword.ForeColor = System.Drawing.Color.Red; lblErroOldPassword.Visible = true; lblErroOldPassword.Text = "Campos Obligatorios"; txtOldPassword.Focus(); return; } if (txtPasswordNew.Text == "" || string.IsNullOrEmpty(txtPasswordNew.Text)) { if (!string.IsNullOrEmpty(txtOldPassword.Text)) { lblErroOldPassword.Visible = false; } if (txtPasswordNew.Text != "") { lblEerroPass.Visible = false; } lblEerroPass.ForeColor = System.Drawing.Color.Red; lblEerroPass.Visible = true; lblEerroPass.Text = "Campos Obligatorios"; txtPasswordNew.Focus(); return; } if (txtPasswordNew.Text != txtPasswordRepeat.Text) { if (txtPasswordNew.Text != "") { lblEerroPass.Visible = false; } lblErroPasswordRepeat.ForeColor = System.Drawing.Color.Red; lblErroPasswordRepeat.Visible = true; lblErroPasswordRepeat.Text = "Contraseñas NO Coinciden"; txtPasswordNew.Text = ""; txtPasswordNew.Focus(); return; } //encriptamos el password. string passwordOld = CapaDatos.EncryptPassword.GetSHA256(txtOldPassword.Text); string passwordNew = CapaDatos.EncryptPassword.GetSHA256(txtPasswordNew.Text); usersEntities = users.LoginValidate(SessionUsers.UserName, passwordOld); if (usersEntities == null) { lblErroOldPassword.ForeColor = System.Drawing.Color.Red; lblErroOldPassword.Visible = true; lblErroOldPassword.Text = "La Contraseña No Es Valida"; txtOldPassword.Focus(); } else { lblErroOldPassword.Visible = false; try { int passwordChanged = users.UpdatePassword(SessionUsers.IdUser, passwordNew); if (passwordChanged == 1) { Close(); FrmSuccess frmSuccess = new FrmSuccess("Contraseña Actualizada"); frmSuccess.ShowDialog(); } } catch (Exception es) { MessageBox.Show("error " + es.Message); } } }
private void btnLogin_Click(object sender, EventArgs e) { try { if (txtUserName.Text == "" || string.IsNullOrEmpty(txtUserName.Text)) { if (txtPassword.Text != "") { lbEerroPass.Visible = false; } lbEerroUser.ForeColor = System.Drawing.Color.Red; lbEerroUser.Visible = true; lbEerroUser.Text = "Campos Obligatorios"; txtUserName.Focus(); return; } if (txtPassword.Text == "" || string.IsNullOrEmpty(txtPassword.Text)) { if (txtUserName.Text != "") { lbEerroUser.Visible = false; } lbEerroPass.ForeColor = System.Drawing.Color.Red; lbEerroPass.Visible = true; lbEerroPass.Text = "Campos Obligatorios"; lbEerroPass.Focus(); return; } //encriptamos el password. string password = CapaDatos.EncryptPassword.GetSHA256(txtPassword.Text); usersEntities = users.LoginValidate(txtUserName.Text, password); //luego de validar el user y pass ingresado sean valido. if (usersEntities != null) { //creamos una session //y llenamos los datos del usuariio logueado en nuestras variables globales. SessionUsers.IdUser = usersEntities.IdUser; SessionUsers.IdRol = usersEntities.IdRol; SessionUsers.UserName = usersEntities.UserName; SessionUsers.EmployeeName = usersEntities.EmployeeName; SessionUsers.LastName = usersEntities.LastName; SessionUsers.Email = usersEntities.Emaill; //validamos el rol del usuario que esta logueado switch (usersEntities.IdRol) { case 1: this.Hide(); UserPrivileges.AdminPrivileges(); //Application.Exit(); break; case 2: this.Hide(); UserPrivileges.CashierPrivileges(); //Application.Exit(); break; case 3: MessageBox.Show("No se que hacer contigo " + usersEntities.EmployeeName, "todo bien"); break; } } else { txtUserName.Text = ""; txtPassword.Text = ""; txtUserName.Focus(); MessageBox.Show("Usuario O Contraseseña no son valido ", "Algo no anda bien."); } } catch (Exception ex) { MessageBox.Show("Usuario o Contraseña incorrectos no puede ser ." + ex.Message, "Valla, algo no anda bien!!"); } }