Ejemplo n.º 1
0
 private void Aceptar_Click(object sender, EventArgs e)
 {
     if (cbRol.SelectedIndex != -1 && cbRol.Text != "Cliente")
     {
         var msg = MessageBox.Show(string.Format("Ingresará al sistema con el rol {0}.", cbRol.Text), "Atención", MessageBoxButtons.YesNo);
         if (msg == DialogResult.Yes)
         {
             this.Hide();
             Login login = new Login(new Negocio.Rol().obtenerRolPorId((int)cbRol.SelectedValue));
             login.ShowDialog();
             Close();
         }
     }
     else if (cbRol.Text == "Cliente")
     {
         var msg = MessageBox.Show(string.Format("Ingresará al sistema con el rol {0}.", cbRol.Text), "Atención", MessageBoxButtons.YesNo);
         if (msg == DialogResult.Yes)
         {
             this.Hide();
             Home.formHome h = new Home.formHome();
             h.ShowDialog();
             this.Close();
         }
     }
     else if (cbRol.Text == "" || cbRol.SelectedIndex == -1)
     {
         MessageBox.Show("Debe seleccionar un rol.", "Error");
     }
 }
Ejemplo n.º 2
0
        private void btnIngresar_Click(object sender, EventArgs e)
        {
            try
            {
                string mensaje = string.Empty;
                if (txtUsername.Text.Trim() == string.Empty || txtPassword.Text == string.Empty) { mensaje += "Debe completar ambos campos."; }
                if (!string.IsNullOrEmpty(mensaje)) { throw new Exception(mensaje); }

                Usuario u = new Usuario().obtenerPorUsernameYRol(txtUsername.Text.Trim(), rolActual.idRol);
                if (u == null)
                {
                    throw new Exception("El usuario ingresado no existe.");
                }
                if (u.intentosUsuario == 3)
                {
                    throw new Exception("El usuario esta inhabilitado debido a que ha alcanzado los 3 intentos. Por favor, comuniquese con un administrador del sistema.");
                }
                if (u.passwordUsuario != EncriptadorSHA256.Encode(txtPassword.Text))
                {
                    u.intentosUsuario++;
                    u.actualizar(u);
                    txtPassword.Text = "";
                    txtPassword.Focus();
                    throw new Exception("Usuario y contraseña no coinciden, por favor, ingreselos de nuevo");
                }
                u.intentosUsuario = 0;
                u.resetearIntentos(u.idUsuario);
                MessageBox.Show(string.Format("Bienvenido, {0}.", u.usernameUsuario), "Bienvenido");
                UsuarioLogueado.usuario = u;
                this.Hide();
                Home.formHome f = new Home.formHome();
                f.ShowDialog();
                f.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
        }