Exemplo n.º 1
0
        /// <summary>
        /// Trae un Usuario (sin los datos de los Roles asociados)
        /// </summary>
        public static Usuario getUsuarioSinRoles(String nombre)
        {
            String query = "SELECT * FROM J2LA.Usuarios " +
                            "WHERE usu_username = "******"'" + nombre + "' " +
                            "AND usu_eliminado = 0";
            try
            {

                DataTable usuarioResult = Singleton.conexion.executeQueryTable(query, null, null);

                if (usuarioResult.Rows.Count == 0)
                {
                    throw new Exception("Usuario Inexistente!");
                }

                if ((bool)usuarioResult.Rows[0]["usu_Inhabilitado"])
                {
                    string mensaje = "Usuario Inhabilitado!" + Environment.NewLine +
                                    @"Motivo: " + usuarioResult.Rows[0]["usu_Motivo"];
                    throw new Exception(mensaje);
                }

                Usuario usuario = new Usuario();
                usuario.id = (int)usuarioResult.Rows[0]["usu_Id"];
                usuario.nombre = (string)usuarioResult.Rows[0]["usu_UserName"];
                usuario.pass = (string)usuarioResult.Rows[0]["usu_Pass"];
                usuario.cantidadIntentos = (int)usuarioResult.Rows[0]["usu_Cant_Intentos"];
                usuario.inhabilitado = (bool)(usuarioResult.Rows[0]["usu_Inhabilitado"]);
                usuario.motivo = (string)usuarioResult.Rows[0]["usu_Motivo"].ToString();
                return usuario;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Guarda la cantidad de intentos de logins que fallo el Usuario
 /// </summary>
 public static void setCantidadIntentos(Usuario usuario)
 {
     try
     {
         Singleton.conexion.executeQuerySP("J2LA.setCantidadIntentos", null,
             new String[2, 2] { { "idUsuario", usuario.id.ToString() },
                                 {"cantIntentos", usuario.cantidadIntentos.ToString() }});
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Exemplo n.º 3
0
        private void ConfirmarLogIn()
        {
            if (!Validar())
                return;

            try
            {
                usuario = InterfazBD.getUsuarioSinRoles(this.txtUserName.Text);
                //NOTA: es importante que sea sin roles ya que, de no tenerlos, el user debería poder loguearse igual y ser informado de esto

                //evaluamos si esta bien la contraseña
                if (Funciones.get_hash(txtPass.Text) == usuario.pass) //Login Successful!!
                {

                    limpiarCantidadIntentos();
                    oDTRolesxUsuario = InterfazBD.getUsuarioConRoles(usuario.nombre); //uso local
                    Singleton.cargarUsuario(usuario.nombre);
                    Singleton.sessionRol_Nombre = InterfazBD.getRolNombre(Singleton.sessionRol_Id);
                    validarPrimerIngreso();

                    //Abro forms de acuerdo a la cantidad de Roles asignados
                    if (Singleton.debeCambiarPass)
                    {
                        Funciones.mostrarAlert("Debe cambiar password para proseguir", "Acceso al Sistema");
                        return;
                    }

                    if (oDTRolesxUsuario.Rows.Count == 1)
                    {
                        Singleton.sessionRol_Id = Convert.ToInt32(oDTRolesxUsuario.Rows[0]["rol_Id"]);

                        this.Close(); //Volvemos al Main!
                        return;
                    }
                    else
                    {
                        EleccionRol rolWindow = new EleccionRol();
                        rolWindow.Icon = this.Icon;
                        rolWindow.RolesTable = oDTRolesxUsuario;
                        rolWindow.ShowDialog();

                        if (Singleton.sessionRol_Id != 0)
                            this.Close();

                        return;
                    }
                }
                else  //Wrong Password...
                {
                    //Se debe actualizar el campo usu_cant_intentos de la base de datos
                    usuario.cantidadIntentos++;
                    InterfazBD.setCantidadIntentos(usuario);
                    string strCantIntentos = (3 - usuario.cantidadIntentos).ToString();
                    string mensaje = "Password Incorrecto." + System.Environment.NewLine;

                    if ((3 - usuario.cantidadIntentos) == 0)
                        mensaje = mensaje + "Su usuario ha sido Inhabilitado. Contacte al Administrador del Sistema.";
                    else
                        mensaje = mensaje + "Le quedan " + strCantIntentos + " intentos.";

                    Funciones.mostrarAlert(mensaje, "Acceso al Sistema");
                }
            }
            catch (Exception error)
            {
                Funciones.mostrarAlert(error.Message, "Acceso al Sistema");
            }

            return;
        }