Beispiel #1
0
        public clsParametros()
        {
            //using System.Configuration;
            string EncKeyBase = "";

            EncKeyBase = ConfigurationManager.AppSettings["enc_key_base"].ToString();
            clsEncryption Encryption = new clsEncryption(EncKeyBase);

            string strServer  = ConfigurationManager.AppSettings["Server"].ToString();
            string strCatalog = ConfigurationManager.AppSettings["Catalog"].ToString();
            string strId      = ConfigurationManager.AppSettings["ID"].ToString();
            string strEnc     = ConfigurationManager.AppSettings["ENC"].ToString();

            CodigoModulo = ConfigurationManager.AppSettings["Codigo_Modulo"].ToString();


            strId  = Encryption.fnGetDecrypt(strId);
            strEnc = Encryption.fnGetDecrypt(strEnc);

            StringDeConexion = ConfigurationManager.AppSettings["StringDeConexion"].ToString();
            StringDeConexion = StringDeConexion.Replace("Server={no_edit}", "Server=" + strServer);
            StringDeConexion = StringDeConexion.Replace("Initial Catalog={no_edit}", "Initial Catalog=" + strCatalog);
            StringDeConexion = StringDeConexion.Replace("Database={no_edit}", "Database=" + strCatalog);
            StringDeConexion = StringDeConexion.Replace("User ID={no_edit}", "User ID=" + strId);
            StringDeConexion = StringDeConexion.Replace("Password={no_edit}", "Password=" + strEnc);
        }
Beispiel #2
0
        public ActionResult fnDecrypt(clsEncodeDecode model)
        {
            //using System.Configuration;
            string EncKeyBase = "";

            EncKeyBase = ConfigurationManager.AppSettings["enc_key_base"].ToString();
            clsEncryption enc = new clsEncryption(EncKeyBase);

            if (string.IsNullOrEmpty(model.strToDecode))
            {
                model.strResult2 = "Cadena vacia.. ingrese un valor...";
            }
            else
            {
                model.strResult2 = enc.fnGetDecrypt(model.strToDecode);
            }

            return(PartialView("Index", model));
        }
Beispiel #3
0
        public HttpResponseMessage ValidaAccesoWeb(List <clsModelLoginValidaWeb> pdatos)
        {
            HttpResponseMessage respuesta = new HttpResponseMessage();

            // ===============================================================================
            //                      Para leer el TokenKey
            // ===============================================================================
            // https://www.guidgenerator.com/online-guid-generator.aspx

            clsTokenKey TokenKeyUtil = new clsTokenKey();
            var         headers      = Request.Headers;

            string TokenKey = "";

            if (headers.Contains("TokenKey"))
            {
                TokenKey = headers.GetValues("TokenKey").First();
            }
            if (TokenKey.Length == 0)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Key Missing"));
            }

            if (!TokenKeyUtil.fnGetTokenKeyValido(TokenKey))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Key Invalid or Inactive"));
            }
            // ===============================================================================



            List <clsModelLoginMensaje> lResult = new List <clsModelLoginMensaje>();

            try
            {
                string Usuario = pdatos[0].Usuario;
                string Token   = pdatos[0].Token;
                string Opcion  = pdatos[0].Opcion;

                string[] arrOpc = Opcion.Split('|');

                // Desencripta el token y valida que la primera parte
                // sea el usuario, la segunda la llave que esta en
                // el web config del api
                // con el usuario lo compara con el usuario que se recibe
                // opcion trae en un split el nombre del controlador y la accion para
                // buscarlo en la tabla de seguridad

                string EncKeyBase   = "";
                string CodigoModulo = "";
                EncKeyBase   = ConfigurationManager.AppSettings["enc_key_base"].ToString();
                CodigoModulo = ConfigurationManager.AppSettings["Codigo_Modulo"].ToString();
                clsEncryption enc = new clsEncryption(EncKeyBase);

                Token = enc.fnGetDecrypt(Token);
                string[] arr = Token.Split('|');

                if (arr.Length != 3)
                {
                    // longitud de token inválida
                    respuesta = Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Inválido L!=3");
                }
                else
                {
                    if (Usuario != arr[0])
                    {
                        // la primera parte del token no es igual al usuario
                        respuesta = Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Inválido L0!=USR");
                    }
                    else
                    {
                        if (EncKeyBase != arr[1])
                        {
                            // la segunda parte del token no es la llave
                            respuesta = Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Inválido L1!=KEY");
                        }
                        else
                        {
                            // valida acceso a la opcion
                            if (fnGetUsuarioConAcceso(Usuario, CodigoModulo, arrOpc[0], arrOpc[1]))
                            {
                                clsModelLoginMensaje Mensaje = new clsModelLoginMensaje();
                                Mensaje.Mensaje = "Token Válido";
                                lResult.Add(Mensaje);
                                respuesta = Request.CreateResponse(HttpStatusCode.OK, lResult);
                            }
                            else
                            {
                                respuesta = Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Inválido L3!=OPC");
                            }
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                respuesta = Request.CreateErrorResponse(HttpStatusCode.Conflict, ex.Message.ToString() + ' ' + ex.InnerException.Message.ToString());
            }

            return(respuesta);
        }
Beispiel #4
0
        public HttpResponseMessage Ingreso(List <clsModelLogin> pdatos)
        {
            HttpResponseMessage respuesta = new HttpResponseMessage();

            try
            {
                // ===============================================================================
                //                      Para leer el TokenKey
                // ===============================================================================
                // https://www.guidgenerator.com/online-guid-generator.aspx

                clsTokenKey TokenKeyUtil = new clsTokenKey();
                var         headers      = Request.Headers;

                string TokenKey = "";
                if (headers.Contains("TokenKey"))
                {
                    TokenKey = headers.GetValues("TokenKey").First();
                }
                if (TokenKey.Length == 0)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Key Missing"));
                }

                if (!TokenKeyUtil.fnGetTokenKeyValido(TokenKey))
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Key Invalid or Inactive"));
                }
                // ===============================================================================

                string Usuario  = pdatos[0].Usuario;
                string ClaveEnc = pdatos[0].EncPass;
                string Clave    = "";

                List <clsModelLogin> lResult = fnGetUsuarioParaValidar(Usuario);

                //Con los datos de usuario se valida clave
                //using System.Configuration;
                string EncKeyBase = "";
                EncKeyBase = ConfigurationManager.AppSettings["enc_key_base"].ToString();
                clsEncryption enc = new clsEncryption(EncKeyBase);
                Clave = enc.fnGetDecrypt(ClaveEnc);

                if (ClaveEnc == "")
                {
                    respuesta = Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Clave en blanco no ingresada");
                }
                else
                {
                    if (Clave == "")
                    {
                        respuesta = Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Clave con encripcion incorrecta");
                    }
                    else
                    {
                        if (lResult.Count == 0)
                        {
                            //usuario no existe
                            respuesta = Request.CreateResponse(HttpStatusCode.Unauthorized, "Usuario No Existe");
                        }
                        else
                        {
                            // Se valida que la clave sea la correcta
                            if (Clave == lResult[0].EncPass)
                            {
                                if (lResult[0].Estado == "AC")
                                {
                                    //en esta variabe se recibe el password desde la base de datos sin encripcion
                                    //se devuelve al cliente encriptada
                                    lResult[0].EncPass = enc.fnGetEncrypt(lResult[0].EncPass);
                                    //calcula token por usuario
                                    lResult[0].Token = enc.fnGetTokenByUser(lResult[0].Usuario);
                                    respuesta        = Request.CreateResponse(HttpStatusCode.OK, lResult);
                                }
                                else
                                {
                                    respuesta = Request.CreateResponse(HttpStatusCode.Unauthorized, "Usuario Bloqueado");
                                }
                            }
                            else
                            {
                                respuesta = Request.CreateResponse(HttpStatusCode.Unauthorized, "Clave incorrecta");
                            }
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                respuesta = Request.CreateErrorResponse(HttpStatusCode.Conflict, ex.Message.ToString() + ' ' + ex.InnerException.Message.ToString());
            }

            return(respuesta);
        }
Beispiel #5
0
        public clsParametros()
        {
            //using System.Configuration;
            string EncKeyBase = "";

            EncKeyBase = ConfigurationManager.AppSettings["enc_key_base"].ToString();
            clsEncryption Encryption = new clsEncryption(EncKeyBase);

            string DBMS = ConfigurationManager.AppSettings["DBMS"].ToString();

            string strServer  = "";
            string strCatalog = "";
            string strId      = "";
            string strEnc     = "";

            // Para el string remoto (Azure)
            strServer  = ConfigurationManager.AppSettings["Server_remoto"].ToString();
            strCatalog = ConfigurationManager.AppSettings["Catalog_remoto"].ToString();
            strId      = ConfigurationManager.AppSettings["ID_remoto"].ToString();
            strEnc     = ConfigurationManager.AppSettings["ENC_remoto"].ToString();
            strId      = Encryption.fnGetDecrypt(strId);

            strEnc = Encryption.fnGetDecrypt(strEnc);
            StringDeConexionRemoto = ConfigurationManager.AppSettings["StringDeConexion_remoto"].ToString();

            StringDeConexionRemoto = StringDeConexionRemoto.Replace("Server={no_edit}", "Server=" + strServer);
            StringDeConexionRemoto = StringDeConexionRemoto.Replace("Initial Catalog={no_edit}", "Initial Catalog=" + strCatalog);
            StringDeConexionRemoto = StringDeConexionRemoto.Replace("Database={no_edit}", "Database=" + strCatalog);
            StringDeConexionRemoto = StringDeConexionRemoto.Replace("User ID={no_edit}", "User ID=" + strId);
            StringDeConexionRemoto = StringDeConexionRemoto.Replace("Password={no_edit}", "Password="******"sql_server":
                strServer  = ConfigurationManager.AppSettings["Server_sql"].ToString();
                strCatalog = ConfigurationManager.AppSettings["Catalog_sql"].ToString();
                strId      = ConfigurationManager.AppSettings["ID_sql"].ToString();
                strEnc     = ConfigurationManager.AppSettings["ENC_sql"].ToString();

                strId  = Encryption.fnGetDecrypt(strId);
                strEnc = Encryption.fnGetDecrypt(strEnc);

                StringDeConexion = ConfigurationManager.AppSettings["StringDeConexion_SQl"].ToString();
                StringDeConexion = StringDeConexion.Replace("Server={no_edit}", "Server=" + strServer);
                StringDeConexion = StringDeConexion.Replace("Initial Catalog={no_edit}", "Initial Catalog=" + strCatalog);
                StringDeConexion = StringDeConexion.Replace("Database={no_edit}", "Database=" + strCatalog);
                StringDeConexion = StringDeConexion.Replace("User ID={no_edit}", "User ID=" + strId);
                StringDeConexion = StringDeConexion.Replace("Password={no_edit}", "Password="******"db2":
                strServer = ConfigurationManager.AppSettings["Server_db2"].ToString();
                strId     = ConfigurationManager.AppSettings["ID_db2"].ToString();
                strEnc    = ConfigurationManager.AppSettings["ENC_db2"].ToString();

                strId = Encryption.fnGetDecrypt(strId);

                strEnc = Encryption.fnGetDecrypt(strEnc);

                StringDeConexion = ConfigurationManager.AppSettings["StringDeConexion_db2"].ToString();

                StringDeConexion = StringDeConexion.Replace("Data Source={no_edit}", "Data Source=" + strServer);

                StringDeConexion = StringDeConexion.Replace("User ID={no_edit}", "User ID=" + strId);
                StringDeConexion = StringDeConexion.Replace("Password={no_edit}", "Password="******"Codigo_Modulo"].ToString();

            FireBaseDb       = ConfigurationManager.AppSettings["FIREBASEDB"].ToString();
            FireBaseCoreData = ConfigurationManager.AppSettings["FIREBASEDB_CORE_NODE"].ToString();
            FireBaseAppData  = ConfigurationManager.AppSettings["FIREBASEDB_APP_NODE"].ToString();
            BitacoraGrabar   = ConfigurationManager.AppSettings["BitacoraGrabar"].ToString();
            BitacoraFile     = ConfigurationManager.AppSettings["BitacoraFile"].ToString();
        }