public void ChangeUserPassword(int userId, string password)
        {
            User user = this.SearchUser(userId);

            user.Password = CypherService.CypherContentNoSalt(password);
            this.context.SaveChanges();
        }
示例#2
0
        public IActionResult CifradoHash
            (String contenido, String resultado, String accion)
        {
            String res = CypherService.EncriptarTextoBasico(contenido);

            //SOLAMENTE SI ESCRIBIMOS EL MISMO CONTENIDO
            //TENDRIAMOS LA MISMA SECUENCIA DE SALIDA
            if (accion.ToLower() == "cifrar")
            {
                ViewData["RESULTADO"] = res;
            }
            else if (accion.ToLower() == "comparar")
            {
                //COMPARAMOS LA CAJA DE TEXTO resultado
                //CON EL DATO YA CIFRADO DE NUEVO res
                //contenido = 12345  --> resultado = 243rea
                //comparar:
                //contenido = 1234556  -->  res = 243redsaa, resultado = 243rea
                if (resultado != res)
                {
                    ViewData["MENSAJE"] =
                        "<h1 style='color:red'>No son iguales</h1>";
                }
                else
                {
                    ViewData["MENSAJE"] =
                        "<h1 style='color:blue'>Iguales</h1>";
                }
            }


            return(View());
        }
示例#3
0
        public Usuario UserLogIn(string username, String password)
        {
            //PARA VALIDAR, NOSOTROS SOLO PODEMOS BUSCAR POR USERNAME
            Usuario user =
                this.context.Usuarios.Where(z => z.UserName == username)
                .FirstOrDefault();

            if (user == null)
            {
                return(null);
            }
            else
            {
                String salt         = user.Salt;
                byte[] passbbdd     = user.Password;
                byte[] passtemporal =
                    CypherService.CifrarContenido(password, salt);
                //COMPARAR ARRAY BYTES[]
                bool respuesta =
                    ToolkitService.CompararArrayBytes(passbbdd, passtemporal);
                if (respuesta == true)
                {
                    return(user);
                }
                else
                {
                    return(null);
                }
            }
        }
示例#4
0
        public Usuario Login(String username, String password)
        {
            Usuario user = this.context.Usuarios.Where(z => z.UserName == username)
                           .FirstOrDefault();

            if (user == null)
            {
                return(null);
            }
            else
            {
                String salt     = user.Salt;
                byte[] passbbdd = user.Password;
                byte[] passform = CypherService.CifrarContenido(password, salt);
                bool   resp     = HelperToolKit.CompararArrayBytes(passbbdd, passform);
                if (resp == true)
                {
                    return(user);
                }
                else
                {
                    return(null);
                }
            }
        }
示例#5
0
        public IActionResult CifradoHashEficiente(String contenido
                                                  , int iteraciones, String salt, String resultado, String accion)
        {
            String cifrado =
                CypherService.CifrarContenido(contenido, iteraciones, salt);

            if (accion.ToLower() == "cifrar")
            {
                ViewData["RESULTADO"] = cifrado;
            }
            else if (accion.ToLower() == "comparar")
            {
                if (resultado == cifrado)
                {
                    ViewData["MENSAJE"] =
                        "<h1 style='color:blue'>Son Iguales!!!</h1>";
                }
                else
                {
                    ViewData["MENSAJE"] =
                        "<h1 style='color:red'>Resultado Incorrecto</h1>";
                }
            }
            return(View());
        }
        public Usuario LoginUsuario(String username, String password)
        {
            if (this.UserNameExists(username))
            {
                Usuario user = this.context.Usuarios.Where(z => z.UserName.ToUpper() == username.ToUpper()).FirstOrDefault();
                if (user == null)
                {
                    return(null);
                }
                else if (!user.Validado)
                {
                    return(null);
                }
                else
                {
                    String salt         = user.Salt;
                    byte[] passbbdd     = user.Password;
                    byte[] passtemporal = CypherService.CifrarContenido(password, salt);

                    bool respuesta = ToolkitService.CompararArrayBytes(passbbdd, passtemporal);
                    if (respuesta)
                    {
                        return(user);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            else
            {
                return(null);
            }
        }
 public void CreateUser(User user)
 {
     user.UserId = this.GetNextId("user");
     //user.Salt = CypherService.GetSalt();
     user.Password = CypherService.CypherContentNoSalt(user.PasswordString /*, user.Salt*/);
     user.Role     = "NormalUser";
     this.context.User.Add(user);
     this.context.SaveChanges();
 }
        public void CambiarContraseña(int idusuario, String password)
        {
            Usuario user = this.BuscarUsuario(idusuario);

            String salt = CypherService.GetSalt();

            user.Salt     = salt;
            user.Password = CypherService.CifrarContenido(password, salt);

            this.context.SaveChanges();
        }
示例#9
0
        public void InsertarUsuario(int idusuario, string nombre, string username, string password)
        {
            Usuario user = new Usuario();

            user.IdUsuario = idusuario;
            user.Nombre    = nombre;
            user.UserName  = username;
            string salt = CypherService.GetSalt();

            user.Salt = salt;
            byte[] respuesta = CypherService.CifrarContenido(password, salt);
            user.Password = respuesta;
            this.context.Usuarios.Add(user);
            this.context.SaveChanges();
        }
        public void InsertUser(string nombre, string username, string password)
        {
            Usuario user = new Usuario();

            //user.idUser = GetMaxIdUser();
            //en el 1º registro estamos obligados a meterle el
            //valor a cañon para que no nos falle el codigo en
            //el metodo incremental
            user.idUser = 1;
            user.name   = nombre;
            user.user   = username;
            String salt = CypherService.GetSalt();

            user.salt = salt;
            byte[] respuesta = CypherService.CypherHashefficent(password, salt);
            user.pswd = respuesta;
            this.context.Usuarios.Add(user);
            this.context.SaveChanges();
        }
示例#11
0
        public User ExisteUsuario(string username, string password)
        {
            User user = this.context.User.Where(x => x.Username == username).FirstOrDefault();

            //String salt = user.Salt;
            byte[] passbbdd     = user.Password;
            byte[] passtemporal =
                CypherService.CypherContentNoSalt(password /*, salt*/);
                        //COMPARAR ARRAY BYTES[]
                        bool respuesta = HelperToolkit.CompararArrayBytes(passbbdd, passtemporal);

            if (respuesta == true)
            {
                return(user);
            }
            else
            {
                return(null);
            }
        }
示例#12
0
        public IActionResult CifradoHashEficiente(string contenido, int iteraciones, string salt, string resultado, string accion)
        {
            var res = CypherService.CifrarContenido(contenido, iteraciones, salt);

            if (accion.ToLower() == "cifrar")
            {
                ViewBag.Resultado = res;
            }
            else if (accion.ToLower() == "comparar")
            {
                if (resultado != res)
                {
                    ViewBag.Mensaje = "Resultados NO iguales";
                }
                else
                {
                    ViewBag.Mensaje = "Resultados iguales";
                }
            }
            return(View());
        }
示例#13
0
        public IActionResult CifradoHash(string contenido, string resultado, string accion)
        {
            var res = CypherService.EncriptarTextoBasico(contenido);

            if (accion.ToLower() == "cifrar")
            {
                ViewBag.Resultado = res;
            }
            else if (accion.ToLower() == "comparar")
            {
                if (resultado != res)
                {
                    ViewBag.Mensaje = "Resultados NO iguales";
                }
                else
                {
                    ViewBag.Mensaje = "Resultados iguales";
                }
            }
            return(View());
        }
示例#14
0
        public Usuario UserLogin(string username, string password)
        {
            Usuario user = this.context.Usuarios.Where(x => x.UserName == username).FirstOrDefault();

            if (user == null)
            {
                return(null);
            }
            string salt = user.Salt;

            byte[] passddbb  = user.Password;
            byte[] passuser  = CypherService.CifrarContenido(password, salt);
            bool   respuesta = HelperToolkit.CompararArrayBytes(passddbb, passuser);

            if (respuesta)
            {
                return(user);
            }
            else
            {
                return(null);
            }
        }
        public void InsertarUsuario(String username, String nombre, String correo, String password, String direccion, String telefono)
        {
            if (!this.UserNameExists(username))
            {
                Usuario user = new Usuario();
                user.IdUsuario = this.GetMaxId(Tablas.Usuarios);
                user.UserName  = username;
                user.Nombre    = nombre;
                user.Correo    = correo;
                user.Direccion = direccion;
                user.Telefono  = telefono;

                String salt = CypherService.GetSalt();
                user.Salt     = salt;
                user.Password = CypherService.CifrarContenido(password, salt);

                user.Validado = true;
                user.Rol      = 0;

                this.context.Usuarios.Add(user);
                this.context.SaveChanges();
            }
        }
示例#16
0
        public void Insert(String nombre, String username, String password)
        {
            Usuario user = new Usuario();

            user.IdUsuario = this.GetMaxIdUsuario();
            user.Nombre    = nombre;
            user.UserName  = username;
            String salt = CypherService.GetSalt();

            user.Salt = salt;
            byte[] respuesta = CypherService.CifrarContenido(password, salt);
            user.Password = respuesta;
            this.context.Usuarios.Add(user);
            this.context.SaveChanges();
            //CON PROCEDIMIENTO
            //String sql = "insertarusuario @username, @pass, @nombre, @salt";
            //SqlParameter parusername = new SqlParameter("@username", username);
            //SqlParameter parnombre = new SqlParameter("@nombre", nombre);
            //String salt = CypherService.GetSalt();
            //SqlParameter parsalt = new SqlParameter("@salt", salt);
            //byte[] passcifrada = CypherService.CifrarContenido(password, salt);
            //SqlParameter parpass = new SqlParameter("@pass", passcifrada);
            //this.context.Database.ExecuteSqlRaw(sql, parusername, parpass, parnombre, parsalt);
        }
        //Comparative credentials
        public Usuario UserLogin(string UserName, string pswd)
        {
            Usuario user = this.context.Usuarios.Where(z => z.user == UserName).FirstOrDefault();

            if (user == null)
            {
                return(null);
            }
            else
            {
                string salt         = user.salt;
                byte[] Pswdbbdd     = user.pswd;
                byte[] PswdTemporal = CypherService.CypherHashefficent(pswd, salt);
                bool   answer       = ToolKit.ArraysComparative(Pswdbbdd, PswdTemporal);
                if (answer == true)
                {
                    return(user);
                }
                else
                {
                    return(null);
                }
            }
        }
示例#18
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: public void dispatch(Object o, final com.sun.jersey.api.core.HttpContext httpContext)
        public override void Dispatch(object o, HttpContext httpContext)
        {
            RepresentationWriteHandler representationWriteHandler = DO_NOTHING;

            LoginContext loginContext = AuthorizedRequestWrapper.getLoginContextFromHttpContext(httpContext);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.factory.GraphDatabaseFacade graph = database.getGraph();
            GraphDatabaseFacade graph = _database.Graph;

            if (o is RestfulGraphDatabase)
            {
                RestfulGraphDatabase restfulGraphDatabase = ( RestfulGraphDatabase )o;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.Transaction transaction = graph.beginTransaction(org.neo4j.kernel.api.KernelTransaction.Type.implicit, loginContext);
                Transaction transaction = graph.BeginTransaction(KernelTransaction.Type.@implicit, loginContext);

                restfulGraphDatabase.OutputFormat.RepresentationWriteHandler = representationWriteHandler = new CommitOnSuccessfulStatusCodeRepresentationWriteHandler(httpContext, transaction);
            }
            else if (o is BatchOperationService)
            {
                BatchOperationService batchOperationService = ( BatchOperationService )o;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.Transaction transaction = graph.beginTransaction(org.neo4j.kernel.api.KernelTransaction.Type.explicit, loginContext);
                Transaction transaction = graph.BeginTransaction(KernelTransaction.Type.@explicit, loginContext);

                batchOperationService.RepresentationWriteHandler = representationWriteHandler = new CommitOnSuccessfulStatusCodeRepresentationWriteHandler(httpContext, transaction);
            }
            else if (o is CypherService)
            {
                CypherService cypherService = ( CypherService )o;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.Transaction transaction = graph.beginTransaction(org.neo4j.kernel.api.KernelTransaction.Type.explicit, loginContext);
                Transaction transaction = graph.BeginTransaction(KernelTransaction.Type.@explicit, loginContext);

                cypherService.OutputFormat.RepresentationWriteHandler = representationWriteHandler = new CommitOnSuccessfulStatusCodeRepresentationWriteHandler(httpContext, transaction);
            }
            else if (o is DatabaseMetadataService)
            {
                DatabaseMetadataService databaseMetadataService = ( DatabaseMetadataService )o;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.Transaction transaction = graph.beginTransaction(org.neo4j.kernel.api.KernelTransaction.Type.implicit, loginContext);
                Transaction transaction = graph.BeginTransaction(KernelTransaction.Type.@implicit, loginContext);

                databaseMetadataService.RepresentationWriteHandler = representationWriteHandler = new RepresentationWriteHandlerAnonymousInnerClass(this, transaction);
            }
            else if (o is ExtensionService)
            {
                ExtensionService extensionService = ( ExtensionService )o;
                extensionService.OutputFormat.RepresentationWriteHandler = representationWriteHandler = new RepresentationWriteHandlerAnonymousInnerClass2(this, loginContext, graph);
            }

            try
            {
                _requestDispatcher.dispatch(o, httpContext);
            }
            catch (Exception e)
            {
                representationWriteHandler.OnRepresentationFinal();

                throw e;
            }
        }