示例#1
0
        public void CreateHash_NullInput_Throws()
        {
            // Arrange
            var algorithm = new PBKDF2();

            // Act && Assert
            Assert.Throws <ArgumentNullException>(() => algorithm.CreateHash(null));
        }
示例#2
0
        public void Expect_Equal()
        {
            var hash = Convert.FromBase64String("+WqsZSS2m8iId8QQAayiIS6bLUj4R/Caem72blANo20=");
            var salt = Convert.FromBase64String("fcOMenFOG3yx8khQ4m0MMAIhhHZ1qKLD4wH23CH8hCs=");

            var result = PBKDF2.CreateHash("echoes", salt, 64000, hash.Length);

            Assert.AreEqual(hash, result);
        }
示例#3
0
        public void IsThisAlgorithm_ValidInput_ReturnsTrue()
        {
            // Arrange
            var algorithm = new PBKDF2();

            // Act
            var hash            = algorithm.CreateHash("Hello world");
            var isThisAlgorithm = algorithm.IsThisAlgorithm(hash);

            // Assert
            Assert.True(isThisAlgorithm);
        }
示例#4
0
        public void CreateHash_ProperInput_Hashes()
        {
            // Arrange
            var algorithm = new PBKDF2();

            // Act
            var hash = algorithm.CreateHash("Hello world");

            // Assert
            Assert.NotNull(hash);
            Assert.NotEmpty(hash);
        }
示例#5
0
        public void CreateHash_EmptyInput_Hashes()
        {
            // Arrange
            var algorithm = new PBKDF2();

            // Act
            var hash = algorithm.CreateHash(string.Empty);

            // Assert
            Assert.NotNull(hash);
            Assert.NotEmpty(hash);
        }
示例#6
0
        public void ValidateHash_MatchingHash_ReturnsTrue()
        {
            // Arrange
            var algorithm = new PBKDF2();

            // Act
            var helloWorldHash = algorithm.CreateHash("Hello world");
            var validHash      = algorithm.ValidateHash("Hello world", helloWorldHash);

            // Assert
            Assert.True(validHash);
        }
示例#7
0
        public void ValidateHash_NotMatchingHash_ReturnsFalse()
        {
            // Arrange
            var algorithm = new PBKDF2();

            // Act
            var helloWorldHash = algorithm.CreateHash("Hello world");
            var validHash      = algorithm.ValidateHash("Definately not hello world", helloWorldHash);

            // Assert
            Assert.False(validHash);
        }
示例#8
0
 public int Register(string email, string password, string url)
 {
     if (ValidEmailFormatCheck(email))
     {
         if (!EmailExistsCheck(email))
         {
             if (ValidPasswordCheck(password, url))
             {
                 //insert into
                 myHealthPassDb.Users.Add(new User
                 {
                     Email            = email,
                     PasswordHash     = PBKDF2.CreateHash(password),
                     LastUpdated      = DateTime.Now,
                     DateCreated      = DateTime.Now,
                     IsLocked         = false,
                     IsLockedOut      = false,
                     IsDeleted        = false,
                     LockoutTimeStamp = null
                 });
                 myHealthPassDb.SaveChanges();
                 return(1);
             }
             else
             {
                 return(-3);
             }
         }
         else
         {
             return(-2);
         }
     }
     else
     {
         return(-1);
     }
 }