public void GenerateSaltReturns44Chars()
 {
     var passwordManager = new PasswordManager(null);
     var salt = passwordManager.GenerateSalt();
     Console.WriteLine(salt);
     Assert.AreEqual(44, salt.Length);
 }
Example #2
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 HashPasswordReturnsConsistentResult()
 {
     const string password = "******";
     var passwordManager = new PasswordManager(null);
     var salt = passwordManager.GenerateSalt();
     var hash1 = passwordManager.HashPassword(password, salt);
     var hash2 = passwordManager.HashPassword(password, salt);
     Assert.AreEqual(hash1, hash2);
 }
 public void HashPasswordReturns44Chars()
 {
     const string password = "******";
     var passwordManager = new PasswordManager(null);
     var salt = passwordManager.GenerateSalt();
     var hash = passwordManager.HashPassword(password, salt);
     Console.WriteLine(hash);
     Assert.AreEqual(44, hash.Length);
 }
 public void GenerateSecurePhraseQuestionOfLength2NeverReturnsTwoSameCharacters()
 {
     var passwordManager = new PasswordManager(null);
     for (int i = 0; i < 1000; ++i)
     {
         var question = passwordManager.GetSecurePhraseQuestion(2);
         Assert.AreEqual(0, question.Item1);
         Assert.AreEqual(1, question.Item2);
     }
 }
 public void GenerateSecurePhraseQuestionNeverReturnsTwoSameCharacters()
 {
     var passwordManager = new PasswordManager(null);
     for (int length = 3; length < 11; ++length)
     {
         for (int i = 0; i < 1000; ++i)
         {
             var question = passwordManager.GetSecurePhraseQuestion(length);
             Assert.AreNotEqual(question.Item1, question.Item2);
             Assert.Greater(question.Item2, question.Item1);
         }
     }
 }
Example #7
0
 public static Facade CreateFacade()
 {
     var database = new Database();
     var configuration = new Configuration();
     var passwordManager = new PasswordManager(configuration);
     var securityTokenService = new Arb.WebApi.Resource.Sts.SecurityTokenService();
     var mailSender = new SmtpMailSender();
     var mailConfiguration = new MailConfiguration();
     var mailNotifier = new MailNotifier(mailSender, mailConfiguration);
     var documentStore = new SharePointDocumentStore();
     var facade = new Facade(database, configuration, passwordManager, securityTokenService, mailNotifier, documentStore);
     return facade;
 }
        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);
        }