Esempio n. 1
0
        //Function to create Test Accounts
        public void CreateTestAccounts()
        {
            //inits the HashManager
            hashManager = new HashingManager();

            //inits the DatabaseManager
            dbManager = new DatabaseManager();



            //ints a userList to create multiple accounts
            List <User> uL = new List <User>();

            uL.Add(new User("Adam", "1234"));
            uL.Add(new User("Leif", "4321"));
            uL.Add(new User("Lars", "asd123"));
            uL.Add(new User("Jens", "321dsa"));
            uL.Add(new User("Frank", "qwerty12"));
            uL.Add(new User("Ole", "21ytrewq"));
            uL.Add(new User("Andy", "5x03Meu7J38"));


            foreach (User u in uL)
            {
                //creates custom salt for each user
                byte[] bsalt = hashManager.CreateSalt();

                //creates salted hash for each user
                byte[] hpassword = hashManager.CreateHash(u.Password, bsalt);

                //Inserts user into database, with the username in plaintext and salted hash with the salt, format salt:saltedHash which is base64 encoded.
                dbManager.CreateUser(u.Username, Convert.ToBase64String(bsalt) + ":" + Convert.ToBase64String(hpassword));
            }
        }
Esempio n. 2
0
        public void CreateSalt_Does_Not_Generate_Null()
        {
            // Arrange
            var salt = HashingManager.CreateSalt();

            // Assert
            Assert.IsNotNull(salt);
        }
Esempio n. 3
0
        public void Calling_CreateSalt_Consecutively_Generates_Different_Salt_Strings()
        {
            // Arrange
            var salt1 = HashingManager.CreateSalt();
            var salt2 = HashingManager.CreateSalt();

            // Assert
            Assert.AreNotEqual(salt1, salt2);
        }
Esempio n. 4
0
        public void Same_Plain_Text_Salted_Will_Generate_Different_Salted_Hash()
        {
            // Arrange
            var plainText = "Password1!";

            // Act
            var user1Hash = HashingManager.ComputeHash(plainText, HashingManager.CreateSalt(), HashAlgo.SHA256);
            var user2Hash = HashingManager.ComputeHash(plainText, HashingManager.CreateSalt(), HashAlgo.SHA256);

            // Assert
            Assert.AreNotEqual(user1Hash, user2Hash);
        }
Esempio n. 5
0
        public void ComputeHash_SHA512_Generate_A_String()
        {
            // Arrange
            var salt      = HashingManager.CreateSalt();
            var plainText = "Password1!";

            // Act
            var hash = HashingManager.ComputeHash(plainText, salt, HashAlgo.SHA512);

            // Assert
            Assert.IsInstanceOfType(hash, typeof(string));
        }
Esempio n. 6
0
        public void Same_Salt_And_Same_PlainText_Returns_Verify_True()
        {
            // Arrange
            var salt      = HashingManager.CreateSalt();
            var plainText = "Password1!";

            // Act
            var saltedHash = HashingManager.ComputeHash(plainText, salt, HashAlgo.SHA256);
            var verify     = HashingManager.Verify(plainText, salt, HashAlgo.SHA256, saltedHash);

            // Assert
            Assert.IsTrue(verify);
        }
Esempio n. 7
0
        public void Same_Salt_And_Different_PlainText_Returns_Verify_False()
        {
            // Arrange
            var salt = HashingManager.CreateSalt();
            var originalPlainText  = "Password1!";
            var differentPlainText = "Password2!";

            // Act
            var saltedHash = HashingManager.ComputeHash(originalPlainText, salt, HashAlgo.SHA256);
            var verify     = HashingManager.Verify(differentPlainText, salt, HashAlgo.SHA256, saltedHash);

            // Assert
            Assert.IsFalse(verify);
        }