Ejemplo n.º 1
0
        public ActionResult EditPassword(ChangePassViewModel model)
        {
            Client currentUser = this.GetLoggedUser();

            if (!ModelState.IsValid)
            {
                ModelState.AddModelError(string.Empty, "Por favor, complete todos campos");
            }
            else if (!model.Password.Equals(model.PasswordCheck))
            {
                ModelState.AddModelError("PasswordCheck", "Las contraseñas no coinciden");
            }
            else if (!PasswordUtilities.Compare(model.OldPassword, currentUser.Password, currentUser.PasswordSalt))
            {
                ModelState.AddModelError("OldPassword", "La contraseña actual es incorrecta");
            }
            else  //ModelState.IsValid && model.Password.Equals(model.PasswordCheck) both true
            {
                currentUser.Password = model.Password;
                clientRepository.HashPassword(currentUser);
                clientRepository.UpdateClient(currentUser);
                clientRepository.Save();
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Ejemplo n.º 2
0
        public void Client_HashPasswordAndCompareWithAttemptedPasswords()
        {
            var passSaltInDb = PasswordUtilities.CreateSalt(16);
            var passHashInDb = PasswordUtilities.GenerateSHA256Hash("TestingPassword", passSaltInDb);

            Assert.IsFalse(PasswordUtilities.Compare("TestingPa$$word", passHashInDb, passSaltInDb));
            Assert.IsFalse(PasswordUtilities.Compare("Testing Password", passHashInDb, passSaltInDb));
            Assert.IsFalse(PasswordUtilities.Compare(string.Empty, passHashInDb, passSaltInDb));
            Assert.IsFalse(PasswordUtilities.Compare(null, passHashInDb, passSaltInDb));
            Assert.IsTrue(PasswordUtilities.Compare("TestingPassword", passHashInDb, passSaltInDb));
        }
Ejemplo n.º 3
0
        private Client Authenticate(string username, string password)
        {
            Client client = clientRepository.GetClients().Where(c => c.Email == username).FirstOrDefault();

            if (client == null)
            {
            }
            else if (PasswordUtilities.Compare(password, client.Password, client.PasswordSalt))
            {
                return(client);
            }

            return(null);
        }