| 1 | package Net::IMAP::Server::Command::Login; | ||
| 2 | |||
| 3 | use warnings; | ||
| 4 | use strict; | ||
| 5 | |||
| 6 | use base qw/Net::IMAP::Server::Command/; | ||
| 7 | |||
| 8 | sub validate { | ||
| 9 | my $self = shift; | ||
| 10 | |||
| 11 | return $self->bad_command("Already logged in") | ||
| 12 | unless $self->connection->is_unauth; | ||
| 13 | |||
| 14 | my @options = $self->parsed_options; | ||
| 15 | return $self->bad_command("Not enough options") if @options < 2; | ||
| 16 | return $self->bad_command("Too many options") if @options > 2; | ||
| 17 | |||
| 18 | $self->untagged_response("BAD [ALERT] Plaintext authentication not over SSL is insecure -- your password was just exposed.") | ||
| 19 | unless $self->connection->is_encrypted; | ||
| 20 | |||
| 21 | return $self->no_command("Login is disabled") | ||
| 22 | if $self->connection->capability =~ /\bLOGINDISABLED\b/; | ||
| 23 | |||
| 24 | return 1; | ||
| 25 | } | ||
| 26 | |||
| 27 | sub run { | ||
| 28 | my $self = shift; | ||
| 29 | |||
| 30 | $self->server->auth_class->require || $self->log( 1, $@ ); | ||
| 31 | my $auth = $self->server->auth_class->new; | ||
| 32 | if (not $auth->provides_plain) { | ||
| 33 | $self->bad_command("Protocol failure"); | ||
| 34 | } elsif ( $auth->auth_plain( $self->parsed_options ) ) { | ||
| 35 | $self->connection->auth($auth); | ||
| 36 | $self->ok_completed(); | ||
| 37 | } else { | ||
| 38 | $self->no_command("Invalid login"); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | 1; |