Esempio n. 1
0
        public RespondModel LogIng(string username, string password, string key, string iv)
        {
            RespondModel rm      = new RespondModel();
            var          usuario = UserManager.GetUsuariosPorUserName(username);

            if (usuario.Id == 0)
            {
                rm.SetResponse(false, "Usuario Invalido.");
                return(rm);
            }
            if (usuario.IntentosFallidos == usuario.PerfilSeguridad.IntentosPermitidos)
            {
                usuario.IdEstadoUsuario = 4;
                UserManager.Guardar(usuario);
                rm.SetResponse(false, "Ha sobrepasado la cantidad de intentos permitidos.\nSu cuenta será bloqueada");
                return(rm);
            }
            var pass = AESCripto.DecryptStringAES(usuario.Password, key, iv);

            if (password != pass)
            {
                usuario.IntentosFallidos = usuario.IntentosFallidos + 1;
                UserManager.Guardar(usuario);
                rm.SetResponse(false, "La contraseña no coinciden.\nLe quedan " + (usuario.PerfilSeguridad.IntentosPermitidos - usuario.IntentosFallidos).ToString() + " intentos.");
                return(rm);
            }
            rm.SetResponse(true, "Verificación Exitosa");


            return(rm);
        }
        public string GenerarCodigoValidacionEmailUsuario(int UsuarioId, string key, string iv)
        {
            try
            {
                string codigoString = "";
                int    codigo       = new Random().Next(1000, 9999);
                codigoString = AESCripto.EncryptStringAES(codigo.ToString(), key, iv);
                var CodigoValidaUsuario = CodigoValUsuarioManager.GetCodigoValidacionEmailByUsuario(UsuarioId);
                CodigoValidaUsuario.Codigo          = codigoString;
                CodigoValidaUsuario.FechaExpiracion = DateTime.Now.AddHours(12);
                CodigoValidaUsuario.Tipo            = CodigoValidaUsuario.Tipo ?? "CAE";
                CodigoValidaUsuario.UsuariosId      = CodigoValidaUsuario.UsuariosId == 0 ? UsuarioId : CodigoValidaUsuario.UsuariosId;


                //var response = CodigoValUsuarioManager.Guardar(new CodigoValidacionUsuario { UsuariosId = UsuarioId, Codigo = codigoString, FechaExpiracion = DateTime.Now.AddHours(12), Tipo = "CAE" });
                var response = CodigoValUsuarioManager.Guardar(CodigoValidaUsuario);

                if (response.response)
                {
                    return(codigoString);
                }
                else
                {
                    return(string.Empty);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 3
0
        public RespondModel LogIng(string username, string password, string key, string iv)
        {
            EstadoUsuariosLogic EstadoUsuariosLogic = new EstadoUsuariosLogic();
            RespondModel        rm = new RespondModel();
            var usuario            = UserManager.GetUsuariosPorUserName(username);

            if (usuario.Id == 0)
            {
                rm.SetResponse(false, "Usuario Invalido.");
                return(rm);
            }
            if (!usuario.EstadoUsuarios.CanLogin)
            {
                rm.SetResponse(false, "Su estado no es valido para ingresar.");
                return(rm);
            }
            if (!usuario.EmailConfirmed)
            {
                rm.SetResponse(false, "Usuario no confirmado.");
                return(rm);
            }

            if (usuario.IntentosFallidos == usuario.PerfilSeguridad.IntentosPermitidos)
            {
                usuario.IdEstadoUsuario = 4;
                usuario.EstadoUsuarios  = null;
                UserManager.Guardar(usuario);
                rm.SetResponse(false, "Ha sobrepasado la cantidad de intentos permitidos.\nSu cuenta será bloqueada");
                return(rm);
            }
            var pass = AESCripto.DecryptStringAES(usuario.Password, key, iv);

            if (password != pass)
            {
                usuario.IntentosFallidos = usuario.IntentosFallidos + 1;
                UserManager.Guardar(usuario);
                rm.SetResponse(false, "La contraseña no coinciden.\nLe quedan " + (usuario.PerfilSeguridad.IntentosPermitidos - usuario.IntentosFallidos).ToString() + " intentos.");
                return(rm);
            }
            /*Si pasa todas la pruebas seteamos los parametros a estado normal*/
            usuario.IntentosFallidos   = 0;
            usuario.FechaUltimoIngreso = DateTime.Now;
            UserManager.Guardar(usuario);

            rm.SetResponse(true, "Verificación Exitosa");


            return(rm);
        }
        public static string GetCryptography(eTypeCryptography typeCryptography, string content, string key = null)
        {
            string cryptography = string.Empty;

            try
            {
                if (Validate(typeCryptography, content, key))
                {
                    switch (typeCryptography)
                    {
                    case eTypeCryptography.DES:
                        cryptography = DESCripto.ToCrypt(key, content);
                        break;

                    case eTypeCryptography.AES:
                        cryptography = AESCripto.ToCrypt(key, content);
                        break;

                    case eTypeCryptography.SHA256:
                        cryptography = SHA256.ToCrypt(content);
                        break;

                    case eTypeCryptography.MD5:
                        cryptography = MD5Cript.ToCrypt(content);
                        break;

                    case eTypeCryptography.ZenitPolar:
                        cryptography = Zenit_Polar.ToCript(content);
                        break;

                    case eTypeCryptography.RSA:
                        cryptography = RSACripto.Encrypt(content);
                        break;
                    }
                }

                return(cryptography);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                cryptography = string.Empty;
            }
        }
        public static string GetDescryptography(eTypeCryptography typeCryptography, string content, string key = null)
        {
            string cryptography = string.Empty;

            try
            {
                if (Validate(typeCryptography, content, key))
                {
                    switch (typeCryptography)
                    {
                    case eTypeCryptography.DES:
                        cryptography = DESCripto.ToDescrypt(key, content);
                        break;

                    case eTypeCryptography.AES:
                        cryptography = AESCripto.ToDescrypt(key, content);
                        break;

                    case eTypeCryptography.SHA256:
                    case eTypeCryptography.MD5:
                        throw new Exception("Este algoritmo não permite descriptografia.");

                    case eTypeCryptography.ZenitPolar:
                        cryptography = Zenit_Polar.ToDescript(content);
                        break;

                    case eTypeCryptography.RSA:
                        cryptography = RSACripto.Decrypt(content);
                        break;
                    }
                }

                return(cryptography);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                cryptography = string.Empty;
            }
        }