Exemplo n.º 1
0
        /// <summary>
        ///     Returns true if the provided object has the same values as the current object.
        /// </summary>
        /// <param name="obj">Object to compare.</param>
        /// <returns><c>bool</c></returns>
        public override bool Equals(object obj)
        {
            ProtectedPassword pwd = obj as ProtectedPassword;

            if (pwd == null)
            {
                return(false);
            }

            return(this.Password == pwd.Password && this.Salt == pwd.Salt && this.IterationCount == pwd.IterationCount);
        }
Exemplo n.º 2
0
        public void RandomProtectAndCompareTest()
        {
            const string passwordToProtect = "MyC0013ncrypti0nP@$$w0rd!";

            using (var protector = new PasswordProtector()) {
                ProtectedPassword protectedPassword = protector.Protect(passwordToProtect);
                Assert.NotNull(protectedPassword);

                Assert.NotNull(protectedPassword.Password);

                Assert.True(protectedPassword.Password.Length <= 64); // The Size of SHA-256
                Assert.True(protectedPassword.Password.Length >= 32); // The Size of MD5

                Assert.NotNull(protectedPassword.Salt);
                Assert.True(protectedPassword.IterationCount > 0);

                Assert.True(protector.CompareProtectedPassword(passwordToProtect, protectedPassword));
            }
        }