public ActionResult SinRetorno(String mensaje, String accion, String sha1, String md5, String sha256, String sha512)
 {
     // Si la accion es cifrar
     if (accion == "cifrar")
     {
         // Guardamos en un ViewBag el mensaje introducido
         ViewBag.Mensaje = mensaje;
         // Devolvemos a la vista la lista de Strings con los cifrados
         return(View(CypherHelper.CifradoHash(mensaje)));
         // Si la acción es comparar
     }
     else if (accion == "comparar")
     {
         // Guardamos en un ViewBag el mensaje introducido
         ViewBag.Mensaje = mensaje;
         // Instanciamos una lista de Strings para guardar los cifrados de la vista
         List <String> textoscifrados = new List <String>();
         textoscifrados.Add(sha1);
         textoscifrados.Add(md5);
         textoscifrados.Add(sha256);
         textoscifrados.Add(sha512);
         // Guardamos en ViewBag.Resultados los textos de "Es correcto" o "No coinciden" obtenidos del método CompararTexto
         ViewBag.Resultados = CypherHelper.CompararTexto(mensaje, textoscifrados);
         // Devolvemos los cifrados anteriores
         return(View(textoscifrados));
     }
     return(View());
 }
Exemplo n.º 2
0
        public async Task <IActionResult> Registro(String email, String password, String username, String confirmarEmail, String confirmarPassword)
        {
            ViewData["Email"]    = email;
            ViewData["Username"] = username;
            String mensaje = await repo.ComprobarDisponibilidadAsync(email, username);

            if (mensaje.Length != 0)
            {
                ViewData["Mensaje"] = mensaje;
                return(View());
            }
            else if (password.Length == 0 || (password != confirmarPassword))
            {
                ViewData["Mensaje"] = "La contraseña está vacía o las contraseñas no coinciden";
                return(View());
            }
            else if (email != confirmarEmail)
            {
                ViewData["Mensaje"] = "Los emails introducidos no coinciden";
                return(View());
            }
            else
            {
                String salt       = CypherHelper.GenerarSalt();
                String txtACifrar = password + salt;
                byte[] cifrado    = CypherHelper.CifradoHashSHA256(txtACifrar);
                int    id         = await repo.RegistrarUsuarioAsync(email, cifrado, salt, username);

                return(RedirectToAction("EnviarEmailActivacion", new { id = id, email = email }));
            }
        }
        private SharedContent InsertSharedContent(string name, Table dataTable, string graph = constants.publish)
        {
            SharedContent newItem = dataTable.CreateInstance <SharedContent>();

            newItem.uri = context.GenerateUri(name, graph);
            String cypher = CypherHelper.GenerateCypher <SharedContent>(newItem, name);

            var response = context.GetGraphConnection(graph).ExecuteTableQuery(cypher, null);

            context.StoreUri(newItem.uri, string.Empty, name, newItem, TeardownOption.Graph);
            context.StoreToken($"__URI{context.GetNumberOfStoredUris()}__", newItem.uri);
            return(newItem);
        }
        public async Task CambiarPasswordAsync(int id, String password, String token)
        {
            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(this.url);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(this.header);
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                Usuario u = await this.BuscarUsuarioAsync(id);

                byte[] pass = CypherHelper.CifradoHashSHA256(password + u.Salt);
                u.Password = pass;
                String              data     = JsonConvert.SerializeObject(u);
                StringContent       content  = new StringContent(data, Encoding.UTF8, "application/json");
                HttpResponseMessage response = await client.PutAsync("api/usuarios/cambiarpass", content);
            }
        }
        public Usuario BuscarUsuario(string email, string password)
        {
            Usuario u = this.context.Usuarios.SingleOrDefault(z => z.Email == email);

            if (u != null)
            {
                byte[] passcifrado = CypherHelper.CifradoHashSHA256(password + u.Salt);
                if (CypherHelper.CompararBytes(u.Password, passcifrado))
                {
                    return(u);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
        public ActionResult CifradoRijndael(String texto, String clave, String textocifrado, String accion)
        {
            byte[] clavebyte = new PasswordDeriveBytes(clave, null).GetBytes(32);
            String mensaje   = null;

            switch (accion)
            {
            case "cifrar":
                mensaje = CypherHelper.CifrarTexto(texto, clavebyte);
                break;

            case "descifrar":
                byte[] textobytes = Encoding.Default.GetBytes(textocifrado);
                mensaje = CypherHelper.DescifrarTexto(textobytes, clavebyte);
                break;

            default:
                break;
            }
            ViewBag.Mensaje = mensaje;
            return(View());
        }
 public ActionResult SinRetornoSalt(String texto, String accion, String salt, String sha1, String md5, String sha256, String sha512)
 {
     // Si la acción es cifrar
     if (accion == "cifrar")
     {
         // Llamamos al método que genera el salt aleatorio. Podemos introducirle los caracteres que tendrá.
         salt = CypherHelper.GenerarSalt(25);
         // Concatenamos el salt al texto introducido
         String txtACifrar = texto + salt;
         // Guardamos el texto y el salt en ViewBags para poder mostrarlos en la Vista.
         ViewBag.Mensaje = texto;
         ViewBag.Salt    = salt;
         // Devolvemos los textos cifrados generados por el texto mas el salt
         return(View(CypherHelper.CifradoHash(txtACifrar)));
     }
     // Si la accion es comparar
     else if (accion == "comparar")
     {
         // Concatenamos el texto introducido por el salt generado en el último cifrado realizado
         String txtACifrar = texto + salt;
         // Guardamos el texto y el salt en ViewBags para poder mostrarlos en la Vista
         ViewBag.Mensaje = texto;
         ViewBag.Salt    = salt;
         // Instanciamos una lista de Strings para guardar los textos cifrados del último cifrado realizado
         List <String> textoscifrados = new List <String>();
         textoscifrados.Add(sha1);
         textoscifrados.Add(md5);
         textoscifrados.Add(sha256);
         textoscifrados.Add(sha512);
         // Guardamos en el ViewBag si coinciden o no los textos cifrados
         ViewBag.Resultados = CypherHelper.CompararTexto(txtACifrar, textoscifrados);
         // Devolvemos en el Model los textos cifrados del último cifrado
         return(View(textoscifrados));
     }
     return(View());
 }
Exemplo n.º 8
0
        public async Task <IActionResult> CambiarPass(int id, String passanterior, String passnuevo, String confpassnuevo)
        {
            Usuario u = await repo.BuscarUsuarioAsync(id);

            String salt = u.Salt;

            byte[] txtACifrar = CypherHelper.CifradoHashSHA256(passanterior + salt);
            if (CypherHelper.CompararBytes(txtACifrar, u.Password) == false)
            {
                ViewData["Error"] = "La contraseña anterior no es correcta";
                return(View(u));
            }

            else if (passnuevo.Length < 6)
            {
                ViewData["Error"] = "La longitud de la contraseña nueva debe de tener al menos 6 caractéres";
                return(View(u));
            }
            else if (passnuevo != confpassnuevo)
            {
                ViewData["Error"] = "Las nuevas contraseñas no coinciden";
                return(View(u));
            }
            else if (passanterior == passnuevo)
            {
                ViewData["Error"] = "La contraseña anterior es la misma que la nueva";
                return(View(u));
            }
            else
            {
                String token = HttpContext.Session.GetString("Token");
                await repo.CambiarPasswordAsync(id, passnuevo, token);

                return(RedirectToAction("CerrarSesion", "Manage"));
            }
        }
 private void AddRelationship(string uri1, string uri2, string relationshipName, string graph)
 {
     String cypher   = CypherHelper.AddRelationship("uri", uri1, uri2, relationshipName);
     var    response = context.GetGraphConnection(graph).ExecuteTableQuery(cypher, null);
 }