Esempio n. 1
0
        public void EncryptString_CanEncryptAndDecryptString()
        {
            const string text   = "100% fluffy goodness";
            const string phrase = "cfVMjtOJ8/eJx0037MHNym3awHj9iAUBdM/bmiLUvlc=";

            var cipher    = StringCipher.EncryptString(text, phrase);
            var decrypted = StringCipher.DecryptString(cipher, phrase);

            Assert.Equal(text, decrypted);
        }
Esempio n. 2
0
        public void DecryptString_ThrowsException_WhenIncorrectPassPhraseIsUsed()
        {
            const string text   = "100% fluffy goodness";
            var          phrase = StringCipher.CreateRandomKey();
            var          cipher = StringCipher.EncryptString(text, phrase);

            var newPhrase = StringCipher.CreateRandomKey();

            Assert.Throws <CryptographicException>(
                () => StringCipher.DecryptString(cipher, newPhrase));
        }
Esempio n. 3
0
        public void EncryptString_ThrowsException_WhenPassPhraseIsNull()
        {
            const string goodText   = "100% fluffy goodness";
            const string badText    = " ";
            const string goodPhrase = "cfVMjtOJ8/eJx0037MHNym3awHj9iAUBdM/bmiLUvlc=";
            const string badPhrase  = null;

            Assert.Throws <ArgumentNullException>(
                () => StringCipher.EncryptString(goodText, badPhrase));

            Assert.Throws <ArgumentNullException>(
                () => StringCipher.EncryptString(badText, goodPhrase));
        }
        public async Task <IActionResult> RecuperarPassword(string email)
        {
            if (await _dbAccess.RecuperarCuenta(email))
            {
                string cEmail = StringCipher.EncryptString(email);
                string body   = @"Lamentamos que haya olvidado su contraseña de Hipercor Web, para crear una nueva clique <a href='https://localhost:44315/Tienda/EditarPassword?cEmail=" + cEmail + "'>aquí<a/>";
                _sendEmail.Send(email, "Recuperación de contraseña", body);
                ViewBag.Mensaje = "Ya hemos enviado el email de recuperación, si en unos minutos no ha llegado a su cuenta vuelva a intentarlo mas tarde";
            }
            else
            {
                ViewBag.Mensaje = "La cuenta " + email + " no está registrada en nuestra base de datos, por favor asegurese de escribirla bien o registrese";
            }

            return(View());
        }
 public async Task <IActionResult> Registro(Cliente cliente)
 {
     if (ModelState.IsValid)
     {
         if (!await _dbAccess.CheckEmail(cliente.Email) && await _dbAccess.signup(cliente))
         {
             string EncryptEmail = StringCipher.EncryptString(cliente.Email);
             string body         = "<h1><a href='https://localhost:44315/Tienda/EmailConfirm?cEmail=" + EncryptEmail + "'>Confirmar cuenta</a></h1>";
             _sendEmail.Send(cliente.Email, "Bienvenido a Hipercor, " + cliente.DatosPersonales.Nombre, body);
             return(View("ConfirmarEmail"));
         }
         else
         { // si hay un error en el signup también entraría x aquí, hay que solucionarlo
             ViewData["error"] = "Ese correo electronico ya esta registrado";
             return(View());
         }
     }
     return(View());
 }