Exemple #1
0
 public static UserEntity CreateActiveUser(string email, Role role)
 {
     using (var context = new DatabaseContext())
     {
         var passwordManager = new PasswordManager(new Configuration());
         var salt = passwordManager.GenerateSalt();
         var hashedPassword = passwordManager.HashPassword(Password, salt);
         var enctyptedSecurePhrase = passwordManager.EncryptSecurePhrase(Phrase);
         var user = new UserEntity
         {
             Id = Guid.NewGuid(),
             Email = email,
             FirstName = email,
             LastName = email,
             Role = role,
             UserState = UserState.Activated,
             PasswordSalt = salt,
             HashedPassword = hashedPassword,
             EncryptedSecurePhrase = enctyptedSecurePhrase,
             FirstSecurePhraseQuestionCharacterIndex = 0,
             SecondSecurePhraseQuestionCharacterIndex = 1,
         };
         context.Users.Add(user);
         context.SaveChanges();
         return user;
     }
 }
        public void EncryptSecurePhrase_qqqqqqqqq()
        {
            const string securePhrase = "qqqqqqqqq";

            var mockRepository = new Moq.MockRepository(MockBehavior.Strict);
            var configurationMock = mockRepository.Create<IConfiguration>();
            configurationMock.SetupGet(x => x.SecurePhraseEncryptionKey).Returns(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 });
            configurationMock.SetupGet(x => x.SecurePhraseIv).Returns(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 });
            var configuration = configurationMock.Object;

            var passwordManager = new PasswordManager(configuration);
            var encrypted = passwordManager.EncryptSecurePhrase(securePhrase);
            var decrypted = passwordManager.DecryptSecurePhrase(encrypted);

            Assert.AreEqual(securePhrase, decrypted);
        }