Ejemplo n.º 1
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            xml = new XmlDocument();
            DataSet ds = new DataSet();
            string  Pass_Desencriptado = "";
            string  userDesencriptado  = "";

            IPUsr = ObtenerIPCliente();
            Azteca.Utility.Security.Rijndael _ChyperRijndael = new Azteca.Utility.Security.Rijndael();

            try
            {
                string ruta       = _ChyperRijndael.Transmute(ConfigurationManager.AppSettings["LlavePrivada"], Azteca.Utility.Security.enmTransformType.intDecrypt);
                string Passphrase = "";
                try
                {
                    Passphrase = (string)Registry.LocalMachine.OpenSubKey(_ChyperRijndael.Transmute(ConfigurationSettings.AppSettings["Registro"], Azteca.Utility.Security.enmTransformType.intDecrypt)).GetValue("passphrase");
                }
                catch
                {
                    //Esto es para Win 7 64 bits

                    RegistryKey localKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64);
                    localKey   = localKey.OpenSubKey(_ChyperRijndael.Transmute(ConfigurationSettings.AppSettings["Registro"], Azteca.Utility.Security.enmTransformType.intDecrypt));
                    Passphrase = localKey.GetValue("passphrase").ToString();
                    localKey.Dispose();
                }
                StreamReader stream = new StreamReader(PGPUtil.DesencriptarTexto(txtContraseña.Text,
                                                                                 File.OpenRead(ruta),
                                                                                 null, Passphrase.ToCharArray()).datos);
                StreamReader streamUser = new StreamReader(PGPUtil.DesencriptarTexto(txtUsuario.Text,
                                                                                     File.OpenRead(ruta),
                                                                                     null, Passphrase.ToCharArray()).datos);

                Pass_Desencriptado = stream.ReadToEnd();
                userDesencriptado  = streamUser.ReadToEnd();

                string TipoUsuario = userDesencriptado.ToUpper().Replace("TVA", "").Replace("PTV", "");

                if (isNumeric(TipoUsuario))
                {
                    isUserName = false;
                    UsuarioTVA = userDesencriptado.ToUpper();
                    usuario    = userDesencriptado.ToUpper();
                }
                else
                {
                    isUserName = true;
                    usuario    = userDesencriptado.ToUpper();
                    XmlDocument DatosUsua = MgnTDI_Menus.GetUserDataByNumEmpl("", usuario, "1,2,5");
                    string      NumUsua   = (DatosUsua.GetElementsByTagName("NUMUSUA").Count > 0) ? DatosUsua.GetElementsByTagName("NUMUSUA")[0].InnerText : "";
                    if (userDesencriptado.ToUpper().Contains("TVA"))
                    {
                        UsuarioTVA = "TVA" + NumUsua;
                    }
                    else if (userDesencriptado.ToUpper().Contains("PTV"))
                    {
                        UsuarioTVA = "PTV" + NumUsua;
                    }
                    else
                    {
                        UsuarioTVA = "TVA" + NumUsua;
                    }
                }

                //Primeras Validacion Tipo de Usuario (Red o TVA)

                #region Validaciones de Usuario Bloqueado, Firmado, etc.
                IntentosXIP = MngNegocioBloqueoIP.ConsultaUltimoAccesos();

                if (ValidaIP(IPUsr, IntentosXIP) >= 10)
                {
                    string strMessage = string.Empty;
                    strMessage       += strMessage == string.Empty ? "" : "<br>";
                    strMessage       += " * Su IP ha sido bloqueada";
                    strMessage       += "<br>";
                    tdError.InnerHtml = strMessage;
                    tdError.Visible   = true;
                    txtUsuario.Text   = usuario;
                    GuardaLogAcceso(8);
                    return;
                }


                //Aqui se debe de mandar a validar si el usuario esta bloqueado por Intentos fallidos
                UserBlock = MngNegocioBloqueoUsuario.ConsultaUsuarioBloqueadoXIdUsuario(usuario.ToUpper().ToString(), "1");
                if (UserBlock.Count > 0)
                {
                    //El Usuario ya ha sido bloqueado
                    string strMessage = string.Empty;
                    strMessage       += strMessage == string.Empty ? "" : "<br>";
                    strMessage       += " * El Usuario ha sido bloqueado por : " + UserBlock[0].TipoBloqueo.DescTipoBloqueo;
                    strMessage       += "<br>";
                    strMessage       += "Favor de Solicitar su desbloqueo por DATASEC";
                    tdError.InnerHtml = strMessage;
                    Random random    = new Random();
                    int    NumMsgBox = random.Next(-999999999, 999999999);
                    ClientScript.RegisterStartupScript(Page.GetType(), "AlertBloqueo" + NumMsgBox, "<script>alert('El Usuario ha sido bloqueado por " + UserBlock[0].TipoBloqueo.DescTipoBloqueo + ". Para desbloquearlo deberá realizar la solicitud en DATASEC');</script>");
                    tdError.Visible = true;
                    txtUsuario.Text = usuario;
                    GuardaLogAcceso(9);
                    return;
                }
                #endregion

                string respuesta = string.Empty;

                #region Login
                LDAPUser ldapUser = new LDAPUser();

                if (!validaLlaveMaestra(TipoUsuario, userDesencriptado, Pass_Desencriptado))
                {
                    try
                    {
                        if (isUserName)
                        {
                            ldapUser = ActiveDirectory.GetCurrentUser2(userDesencriptado.ToUpper(), Pass_Desencriptado);
                        }
                        else
                        {
                            ldapUser = ActiveDirectory.GetCurrentUser(userDesencriptado.ToUpper(), Pass_Desencriptado);
                        }
                    }
                    catch { ldapUser = null; }


                    if (ldapUser != null)
                    {
                        if (AutenticaUsuario.Validar("", userDesencriptado, Pass_Desencriptado))
                        {
                            XmlDocument UserData = new XmlDocument();
                            if (isUserName)
                            {
                                UserData = MgnTDI_Menus.GetUserDataByNumEmpl("", ldapUser.LoginName, "1,2,5");
                            }
                            else
                            {
                                UserData   = MgnTDI_Menus.GetUserDataByNumEmpl(ldapUser.EmployeeID, "", "1,2,5");
                                isUserName = true;
                            }
                            ObtieneDatosUsuario(UserData);
                        }
                        else
                        {
                            ValidaBloqueosErrorPass();
                        }
                    }
                    else
                    {
                        ValidaBloqueosErrorPass();
                    }
                }
            }
            catch (Exception ex)
            {
                THE_LogErrores oLogErrores = new THE_LogErrores();
                TDI_EMPL       oEmpl       = new TDI_EMPL();
                oEmpl.EmpleadoLlavePrimaria = !UsuarioTVA.Replace("TVA", "").Trim().Equals(String.Empty) ? int.Parse(UsuarioTVA.Replace("TVA", "")) : 0;
                oLogErrores.CveEmpleado     = oEmpl;
                oLogErrores.DirIP           = IPUsr;
                oLogErrores.Error           = ex.Message + "\n" + ex.StackTrace.ToString();
                oLogErrores.Pantalla        = "Default.aspx";
                oLogErrores.MachineName     = "";
                oLogErrores.FechaCreacion   = DateTime.Now;
                oLogErrores.Dominio         = Request.Url.Host.ToLower();
                MngNegocioLogErrores.GuardarLogErrores(oLogErrores);
                this.div_txtUsuario.InnerHtml = "El usuario no tiene permisos para acceder al sistema";
                GuardaLogAcceso(2);
            }

            #endregion
        }
Ejemplo n.º 2
0
        private bool validaLlaveMaestra(string TipoUsuario, string userDesencriptado, string Pass_Desencriptado)
        {
            try
            {
                string respuesta = string.Empty;
                try
                {
                    if (isNumeric(TipoUsuario))
                    {
                        respuesta = Llave.validaEmpleado(userDesencriptado, Pass_Desencriptado);
                    }
                    else
                    {
                        respuesta = Llave.validaEmpleado(UsuarioTVA, Pass_Desencriptado);
                    }
                    xml.LoadXml(respuesta);
                }
                catch (Exception ex)
                {
                    THE_LogErrores oLogErrores = new THE_LogErrores();
                    TDI_EMPL       oEmpl       = new TDI_EMPL();
                    oEmpl.EmpleadoLlavePrimaria = int.Parse(UsuarioTVA.Replace("TVA", "").Replace("PTV", ""));
                    oLogErrores.CveEmpleado     = oEmpl;
                    oLogErrores.DirIP           = IPUsr;
                    oLogErrores.Error           = ex.Message + "\n" + ex.StackTrace.ToString();
                    oLogErrores.Pantalla        = "Default.aspx";
                    oLogErrores.MachineName     = "";
                    oLogErrores.FechaCreacion   = DateTime.Now;
                    oLogErrores.Dominio         = Request.Url.Host.ToLower();
                    MngNegocioLogErrores.GuardarLogErrores(oLogErrores);
                }

                if ((respuesta.IndexOf("Respuesta=\"[OK]\"") != -1))
                {
                    //Aqui se debe de mandar a validar si el usuario esta bloqueado por Intentos fallidos
                    IList <THE_BloqueoUsuario> UserBlockInactivo = MngNegocioBloqueoUsuario.ConsultaUsuarioBloqueadoXIdUsuario(usuario.ToUpper().ToString(), "2");
                    if (UserBlockInactivo.Count > 0)
                    {
                        //El Usuario ya ha sido bloqueado
                        string strMessage = string.Empty;
                        strMessage += strMessage == string.Empty ? "" : "<br>";
                        strMessage += " * El Usuario ha sido bloqueado por : " + UserBlockInactivo[0].TipoBloqueo.DescTipoBloqueo;
                        strMessage += "<br>";
                        strMessage += "Favor de Solicitar su desbloqueo por DATASEC";
                        Random random    = new Random();
                        int    NumMsgBox = random.Next(-999999999, 999999999);
                        ClientScript.RegisterStartupScript(Page.GetType(), "AlertBloqueoInactivo" + NumMsgBox, "<script>alert('El Usuario ha sido bloqueado por " + UserBlock[0].TipoBloqueo.DescTipoBloqueo + ". Para desbloquearlo deberá realizar la solicitud en DATASEC');</script>");
                        tdError.InnerHtml = strMessage;
                        tdError.Visible   = true;
                        txtUsuario.Text   = usuario;
                        GuardaLogAcceso(9);
                        return(false);
                    }

                    tdError.Visible   = false;
                    tdError.InnerHtml = "";

                    string      numeroUsuario = xml.FirstChild.ChildNodes[0].Attributes["NumEmp"].Value;
                    XmlDocument UserData      = MgnTDI_Menus.GetUserDataByNumEmpl(numeroUsuario, "", "1,2,5");

                    ObtieneDatosUsuario(UserData);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex) {
                return(false);
            }
            return(true);
        }