public void AuthenticationFailsWhenAuthenticationRequestorGivenEmptyPassword()
        {
            var authenticator = new PasswordAuthenticator(_cryptographyProvider, _cipherText, () => new SecureString());
            var authenticated = authenticator.Authenticate(_wrongPassword);

            Assert.That(!authenticated);
        }
        public void ProvidingCorrectPasswordToTheAuthenticationRequestorReturnsTrue()
        {
            var authenticator = new PasswordAuthenticator(_cryptographyProvider, _cipherText, () => _correctPassword);
            var authenticated = authenticator.Authenticate(_wrongPassword);

            Assert.That(authenticated);
        }
        public void AuthenticatingWithWrongPasswordReturnsFalse()
        {
            var authenticator = new PasswordAuthenticator(_cryptographyProvider, _cipherText, () => Optional <SecureString> .Empty);
            var authenticated = authenticator.Authenticate(_wrongPassword);

            Assert.That(!authenticated);
        }
示例#4
0
        private bool Authenticate(string cipherText, SecureString password)
        {
            var authenticator = new PasswordAuthenticator(_cryptographyProvider, cipherText, AuthenticationRequestor);
            var authenticated = authenticator.Authenticate(password);

            if (!authenticated)
            {
                return(false);
            }

            _rootNodeInfo.PasswordString = authenticator.LastAuthenticatedPassword.ConvertToUnsecureString();
            return(true);
        }
        private Optional <SecureString> GetDecryptionKey(SqlConnectionListMetaData metaData)
        {
            var cryptographyProvider = new LegacyRijndaelCryptographyProvider();
            var cipherText           = metaData.Protected;
            var authenticator        = new PasswordAuthenticator(cryptographyProvider, cipherText, AuthenticationRequestor);
            var authenticated        = authenticator.Authenticate(new RootNodeInfo(RootNodeType.Connection).DefaultPassword.ConvertToSecureString());

            if (authenticated)
            {
                return(authenticator.LastAuthenticatedPassword);
            }
            return(Optional <SecureString> .Empty);
        }
        public void AuthenticatorRespectsMaxAttempts()
        {
            var authAttempts = 0;

            Optional <SecureString> AuthenticationRequestor()
            {
                authAttempts++;
                return(_wrongPassword);
            }

            var authenticator = new PasswordAuthenticator(_cryptographyProvider, _cipherText, AuthenticationRequestor);

            authenticator.Authenticate(_wrongPassword);
            Assert.That(authAttempts == authenticator.MaxAttempts);
        }
        public void AuthenticationRequestorNotCalledWhenInitialPasswordIsCorrect()
        {
            var wasCalled = false;

            Optional <SecureString> AuthenticationRequestor()
            {
                wasCalled = true;
                return(_correctPassword);
            }

            var authenticator = new PasswordAuthenticator(_cryptographyProvider, _cipherText, AuthenticationRequestor);

            authenticator.Authenticate(_correctPassword);
            Assert.That(!wasCalled);
        }
        public void AuthenticatorRespectsMaxAttemptsCustomValue()
        {
            const int customMaxAttempts = 5;
            var       authAttempts      = 0;

            Optional <SecureString> AuthenticationRequestor()
            {
                authAttempts++;
                return(_wrongPassword);
            }

            var authenticator =
                new PasswordAuthenticator(_cryptographyProvider, _cipherText, AuthenticationRequestor)
            {
                MaxAttempts = customMaxAttempts
            };

            authenticator.Authenticate(_wrongPassword);
            Assert.That(authAttempts == customMaxAttempts);
        }
示例#9
0
        private bool Authenticate(string cipherText, SecureString password, RootNodeInfo rootInfo = null)
        {
            var authenticator = new PasswordAuthenticator(_cryptographyProvider, cipherText)
            {
                AuthenticationRequestor = AuthenticationRequestor
            };

            var authenticated = authenticator.Authenticate(password);

            if (!authenticated)
            {
                return(authenticated);
            }
            Runtime.EncryptionKey = authenticator.LastAuthenticatedPassword;
            if (rootInfo == null)
            {
                return(authenticated);
            }
            rootInfo.Password       = true;
            rootInfo.PasswordString = Runtime.EncryptionKey.ConvertToUnsecureString();
            return(authenticated);
        }
        public void AuthenticatingWithCorrectPasswordReturnsTrue()
        {
            var authenticated = _authenticator.Authenticate(_correctPassword);

            Assert.That(authenticated);
        }