public AuthMechanismProcessorStatus ProcessResponse(string data)
        {
            if (data != null)
            {
                State = States.WaitingForUsername;
            }

            switch (State)
            {
            case States.Initial:
                Connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.AuthenticationContinue,
                                                          Convert.ToBase64String(
                                                              Encoding.ASCII.GetBytes("Username:"******"Password:"))));
                State = States.WaitingForPassword;
                return(AuthMechanismProcessorStatus.Continue);

            case States.WaitingForPassword:
                string password = ServerUtility.DecodeBase64(data);
                State = States.Completed;

                Credentials = new LoginAuthenticationCredentials(_username, password);

                AuthenticationResult result =
                    Connection.Server.Behaviour.ValidateAuthenticationCredentials(Connection,
                                                                                  Credentials);

                switch (result)
                {
                case AuthenticationResult.Success:
                    return(AuthMechanismProcessorStatus.Success);

                    break;

                default:
                    return(AuthMechanismProcessorStatus.Failed);

                    break;
                }

            default:
                throw new NotImplementedException();
            }
        }
Пример #2
0
        public async override Task<AuthMechanismProcessorStatus> ProcessResponseAsync(string data)
        {
            if (data != null)
            {
                State = States.WaitingForUsername;
            }

            switch (State)
            {
                case States.Initial:
                    await Connection.WriteResponseAsync(new SmtpResponse(StandardSmtpResponseCode.AuthenticationContinue,
                                                              Convert.ToBase64String(
                                                                  Encoding.ASCII.GetBytes("Username:"******"Password:"))));
                    State = States.WaitingForPassword;
                    return AuthMechanismProcessorStatus.Continue;

                case States.WaitingForPassword:
                    string password = DecodeBase64(data);
                    State = States.Completed;

                    Credentials = new LoginAuthenticationCredentials(_username, password);

                    AuthenticationResult result =
                        await Connection.Server.Behaviour.ValidateAuthenticationCredentialsAsync(Connection,
                                                                                      Credentials);

                    switch (result)
                    {
                        case AuthenticationResult.Success:
                            return AuthMechanismProcessorStatus.Success;

                        default:
                            return AuthMechanismProcessorStatus.Failed;
                    }

                default:
                    throw new NotImplementedException();
            }
        }