AnyEve...e::Auth(3pm)

πŸ“¦ version 0.20, in ubuntu stonking

πŸ’– AnyEvent::FTP::Server::Role::Auth β€” the auth glow-up ✨

okay so bestie, this is a page from the User Contributed Perl Documentation section of the manual, and the whole vibe is: it's AnyEvent::FTP::Server::Role::Auth(3pm), a role that handles the "who even are you" part of an FTP server. Let's get into it πŸ’…


🌸 VERSION

version 0.20 πŸŽ€


✨ SYNOPSIS

So in your context, you're gonna do this whole thing:

package AnyEvent::FTP::Server::Context::MyContext;

use Moo;
extends 'AnyEvent::FTP::Server::Context';
with 'AnyEvent::FTP::Server::Role::Auth';

has '+unauthenticated_safe_commands' => (
  default => sub { [ qw( USER PASS HELP QUIT FOO ) ] },
);

# this command is deemed safe pre auth by
# unauthenticated_safe_commands
sub cmd_foo
{
  my($self, $con, $req) = @_;
  $con->send_response(211 => 'Here to stay');
  $self->done;
}

# this command can pnly be executed after
# authentication
sub cmd_bar
{
  my($self, $con, $req) = @_;
  $con->send_response(211 => 'And another thing');
  $self->done;
}

Then when you actually create your server object, you go:

use AnyEvent:FTP::Server;

my $server = AnyEvent::FTP::Server->new;
$server->on_connect(sub {
  # $con isa AnyEvent::FTP::Server::Connection
  my $con = shift;
  # $context isa AnyEvent::FTP::Server::Context::MyContext
  my $context = $con->context;

  # allow login from user 'user' with password 'secret'
  $context->authenticator(sub {
    my($user, $pass) = @_;
    return $user eq 'user' && $pass eq 'secret';
  });

  # make the client wait 5 seconds if they enter a
  # bad username / password
  $context->bad_authentication_delay(5);
});

like, that's it. that's the whole setup. you're a server now πŸ’–


πŸ‘‘ DESCRIPTION

This role hands you an authentication interface for your AnyEvent::FTP::Server context. it's giving "bouncer at the club door" energy and honestly? iconic.


πŸ¦‹ ATTRIBUTES

user

The user that the last FTP "USER" command asked for. (note the quotes, they're quotes-quotes.)

authenticated

True if the user has successfully logged in. slay.

authenticator

A sub ref used to check username + password combos. By default all authentication requests are refused. so yeah, default behavior is lowkey a locked door β€” no cap, you have to set this yourself.

bad_authentication_delay

Number of seconds to wait after a bad login attempt. the "go sit in the corner and think about what you did" timer πŸ™ˆ

unauthenticated_safe_commands

The list of commands it's safe to execute before the user has authenticated. The default is USER, PASS, HELP and QUIT. everything else has to wait its turn, bestie.


πŸ’… METHODS

auth_command_check_hook

$context->auth_command_check_hook($connection, $command);

This hook checks that any commands executed by the client before authentication are in the "authenticated_safe_commands" list. (yes, that's the name in the original, we don't touch the lore.)

fr fr β€” if a pre-auth command isn't on that list, this hook is the one catching it. keep your list tight.

🌈 COMMANDS

  • USER
  • PASS

those are the commands, that's the list, periodt ✨


🫢 AUTHOR

Author: Graham Ollis <plicease@cpan.org>

Contributors:

  • Ryo Okamoto
  • Shlomi Fish
  • JosΓ© JoaquΓ­n Atria

shoutout to the whole squad, we love a collaborative queen πŸ‘‘


This software is copyright (c) 2017-2022 by Graham Ollis.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


and that's a wrap, bestie πŸŽ€ this page was perl v5.40.1, dated 2026-02-16, from the AnyEve...e::Auth(3pm) man page. go forth and authenticate responsibly πŸ’œ 🧚

πŸ“¦ where this page comes from