Esempio n. 1
0
        public void TestMinMaxIDs()
        {
            var mockTime = new MockTimeManager();
            var passwordManager = new PasswordManager(mockTime);

            Assert.IsTrue(!String.IsNullOrEmpty(passwordManager.CreatePassword(0)));
            Assert.IsTrue(!String.IsNullOrEmpty(passwordManager.CreatePassword(uint.MinValue)));
            Assert.IsTrue(!String.IsNullOrEmpty(passwordManager.CreatePassword(uint.MaxValue)));
        }
Esempio n. 2
0
        public void TestMinMaxIDs()
        {
            var mockTime        = new MockTimeManager();
            var passwordManager = new PasswordManager(mockTime);

            Assert.IsTrue(!String.IsNullOrEmpty(passwordManager.CreatePassword(0)));
            Assert.IsTrue(!String.IsNullOrEmpty(passwordManager.CreatePassword(uint.MinValue)));
            Assert.IsTrue(!String.IsNullOrEmpty(passwordManager.CreatePassword(uint.MaxValue)));
        }
Esempio n. 3
0
        public void TestTimeValidity()
        {
            var mockTime = new MockTimeManager();
            var passwordManager = new PasswordManager(mockTime);

            // Check current time prior to pass creation
            mockTime.Time = 1000;
            string pass1 = passwordManager.CreatePassword(1);

            mockTime.Time -= 1;
            Assert.IsFalse(passwordManager.IsPasswordValid(1, pass1));

            // Check max valid time
            mockTime.Time = 1000;
            pass1 = passwordManager.CreatePassword(1);

            mockTime.Time += passwordManager.TimeValidity;
            Assert.IsTrue(passwordManager.IsPasswordValid(1, pass1));

            // Check max valid time plus 1 ms
            mockTime.Time = 1000;
            pass1 = passwordManager.CreatePassword(1);

            mockTime.Time += passwordManager.TimeValidity + 1;
            Assert.IsFalse(passwordManager.IsPasswordValid(1, pass1));

            // Check time validity increment when generating password to the same user
            mockTime.Time = 1000;
            pass1 = passwordManager.CreatePassword(1);
            mockTime.Time += passwordManager.TimeValidity;
            string pass2 = passwordManager.CreatePassword(1);
            Assert.AreEqual(pass1, pass2);

            mockTime.Time += passwordManager.TimeValidity;
            Assert.IsTrue(passwordManager.IsPasswordValid(1, pass1));

            // Check creating a new pass when time is expired gives a different pass
            mockTime.Time = 1000;
            pass1 = passwordManager.CreatePassword(1);
            mockTime.Time += passwordManager.TimeValidity + 1;
            pass2 = passwordManager.CreatePassword(1);
            Assert.AreNotEqual(pass1, pass2);

            mockTime.Time += passwordManager.TimeValidity;
            Assert.IsTrue(passwordManager.IsPasswordValid(1, pass2));
        }
Esempio n. 4
0
        public void TestExpiredPasswordsDeletion()
        {
            var mockTime = new MockTimeManager();
            var passwordManager = new PasswordManager(mockTime);

            mockTime.Time = 1000;
            string pass1 = passwordManager.CreatePassword(1);
            string pass2 = passwordManager.CreatePassword(2);
            string pass3 = passwordManager.CreatePassword(3);

            mockTime.Time += passwordManager.TimeValidity + 1;
            string pass4 = passwordManager.CreatePassword(4);
            string pass5 = passwordManager.CreatePassword(5);

            Assert.IsTrue(passwordManager.NumPasswordsStored == 5);
            passwordManager.RemoveExpiredPasswords();
            Assert.IsTrue(passwordManager.NumPasswordsStored == 3);
        }
Esempio n. 5
0
        public void TestExpiredPasswordsDeletion()
        {
            var mockTime        = new MockTimeManager();
            var passwordManager = new PasswordManager(mockTime);

            mockTime.Time = 1000;
            string pass1 = passwordManager.CreatePassword(1);
            string pass2 = passwordManager.CreatePassword(2);
            string pass3 = passwordManager.CreatePassword(3);

            mockTime.Time += passwordManager.TimeValidity + 1;
            string pass4 = passwordManager.CreatePassword(4);
            string pass5 = passwordManager.CreatePassword(5);

            Assert.IsTrue(passwordManager.NumPasswordsStored == 5);
            passwordManager.RemoveExpiredPasswords();
            Assert.IsTrue(passwordManager.NumPasswordsStored == 3);
        }
Esempio n. 6
0
        public void TestOneTimeValidity()
        {
            var mockTime = new MockTimeManager();
            var passwordManager = new PasswordManager(mockTime);

            Assert.IsTrue(passwordManager.NumPasswordsStored == 0);
            string pass1 = passwordManager.CreatePassword(1);
            Assert.IsTrue(passwordManager.NumPasswordsStored == 1);
            Assert.IsTrue(passwordManager.IsPasswordValid(1, pass1));
            Assert.IsTrue(passwordManager.NumPasswordsStored == 0);
            Assert.IsFalse(passwordManager.IsPasswordValid(1, pass1));
        }
Esempio n. 7
0
        public static void Main(string[] args)
        {
            IPasswordManager passwordManager = new PasswordManager(new PasswordGenerator());

            while (true)
            {
                Console.WriteLine("Please make a choice:");
                Console.WriteLine("Enter 1 to generate password");
                Console.WriteLine("Enter 2 to log in");
                Console.WriteLine("Enter 3 to exit");
                Console.Write("Option: ");
                var option = Console.ReadLine();
                if (string.IsNullOrEmpty(option))
                {
                    option = "3";
                }
                if (IsNumber(option))
                {
                    string id;
                    string password;

                    var number = int.Parse(option);
                    switch (number)
                    {
                    case 1:
                        Console.Write("Please enter a user id: ");
                        id = Console.ReadLine();

                        password = passwordManager.CreatePassword(id);

                        Console.WriteLine("Generated password for {0} is: {1}", id, password);
                        break;

                    case 2:
                        Console.Write("Please enter user id:");
                        id = Console.ReadLine();

                        Console.Write("Please enter password:"******"Password valid: {0}", passwordManager.IsPasswordCorrectAndValid(id, password));
                        break;

                    case 3:
                        return;

                    default:
                        Console.WriteLine("Invalid option.  Please try again.");
                        break;
                    }
                }
            }
        }
Esempio n. 8
0
        static void DoCreateNewPassword()
        {
            uint?id = ParseUser();

            if (id == null)
            {
                return;
            }

            string pass = sPasswordManager.CreatePassword(id.Value);

            Console.WriteLine("Password for user " + id + " is '" + pass + "'");
        }
Esempio n. 9
0
        public void TestOneTimeValidity()
        {
            var mockTime        = new MockTimeManager();
            var passwordManager = new PasswordManager(mockTime);

            Assert.IsTrue(passwordManager.NumPasswordsStored == 0);
            string pass1 = passwordManager.CreatePassword(1);

            Assert.IsTrue(passwordManager.NumPasswordsStored == 1);
            Assert.IsTrue(passwordManager.IsPasswordValid(1, pass1));
            Assert.IsTrue(passwordManager.NumPasswordsStored == 0);
            Assert.IsFalse(passwordManager.IsPasswordValid(1, pass1));
        }
Esempio n. 10
0
        public void TestTimeValidity()
        {
            var mockTime        = new MockTimeManager();
            var passwordManager = new PasswordManager(mockTime);

            // Check current time prior to pass creation
            mockTime.Time = 1000;
            string pass1 = passwordManager.CreatePassword(1);

            mockTime.Time -= 1;
            Assert.IsFalse(passwordManager.IsPasswordValid(1, pass1));

            // Check max valid time
            mockTime.Time = 1000;
            pass1         = passwordManager.CreatePassword(1);

            mockTime.Time += passwordManager.TimeValidity;
            Assert.IsTrue(passwordManager.IsPasswordValid(1, pass1));

            // Check max valid time plus 1 ms
            mockTime.Time = 1000;
            pass1         = passwordManager.CreatePassword(1);

            mockTime.Time += passwordManager.TimeValidity + 1;
            Assert.IsFalse(passwordManager.IsPasswordValid(1, pass1));

            // Check time validity increment when generating password to the same user
            mockTime.Time  = 1000;
            pass1          = passwordManager.CreatePassword(1);
            mockTime.Time += passwordManager.TimeValidity;
            string pass2 = passwordManager.CreatePassword(1);

            Assert.AreEqual(pass1, pass2);

            mockTime.Time += passwordManager.TimeValidity;
            Assert.IsTrue(passwordManager.IsPasswordValid(1, pass1));

            // Check creating a new pass when time is expired gives a different pass
            mockTime.Time  = 1000;
            pass1          = passwordManager.CreatePassword(1);
            mockTime.Time += passwordManager.TimeValidity + 1;
            pass2          = passwordManager.CreatePassword(1);
            Assert.AreNotEqual(pass1, pass2);

            mockTime.Time += passwordManager.TimeValidity;
            Assert.IsTrue(passwordManager.IsPasswordValid(1, pass2));
        }
Esempio n. 11
0
 private byte[] GetPasswordHash(string login, string password)
 {
     return(PasswordManager.CreatePassword(login, password));
 }