Authen::Htpasswd(3pm)
π Authen::Htpasswd β¨
okay bestie, listen β this is the User Contributed Perl Documentation page for Authen::Htpasswd, and it's literally the cutest little interface to read and modify Apache .htpasswd files. it's giving object-oriented. it's giving password file glow-up. let's go π
πΈ NAME πΈ
Authen::Htpasswd β interface to read and modify Apache .htpasswd files π
π¦ SYNOPSIS π¦
my $pwfile = Authen::Htpasswd->new('user.txt', { encrypt_hash => 'md5' });
# authenticate a user (checks all hash methods by default)
if ($pwfile->check_user_password('bob', 'foo')) { ... }
# modify the file (writes immediately)
$pwfile->update_user('bob', $password, $info);
$pwfile->add_user('jim', $password);
$pwfile->delete_user('jim');
# get user objects tied to a file
my $user = $pwfile->lookup_user('bob');
if ($user->check_password('vroom', [qw/ md5 sha1 /])) { ... } # only use secure hashes
$user->password('foo'); # writes to file
$user->set(password => 'bar', extra_info => 'editor'); # change more than one thing at once
# or manage the file yourself
my $user = Authen::Htpasswd::User->new('bill', { hashed_password => 'iQ.IuWbUIhlPE' });
my $user = Authen::Htpasswd::User->new('bill', 'bar', 'staff', { encrypt_hash => 'crypt' });
print PASSWD $user->to_line, "\n";
β¨ DESCRIPTION β¨
this module is your bestie for Apache-style .htpasswd files β it hands you a convenient, object-oriented interface so you never have to hand-parse one of those bad boys again π«Ά
it supports passwords encrypted via MD5, SHA-1, and crypt, plus plain (cleartext) passwords, no cap.
and if there are extra fields hanging out after the username and password? they're accessible through the extra_info array, periodt π
π METHODS π
π new
my $pwfile = Authen::Htpasswd->new($filename, \%options);
makes you an object for a given .htpasswd file. options are:
encrypt_hashβ how passwords should be encrypted if a user is added or changed. valid values are"md5","sha1","crypt", and"plain". default is"crypt".check_hashesβ an array of hash methods to try when checking a password. the methods get tried in the order you give them. default is"md5","sha1","crypt","plain".
π lookup_user
my $userobj = $pwfile->lookup_user($username);
returns an Authen::Htpasswd::User object for the given user in the password file. iconic behavior honestly π
π all_users
my @users = $pwfile->all_users;
π check_user_password
$pwfile->check_user_password($username,$password);
returns whether the password is valid. it's a shortcut for $pwfile->lookup_user($username)->check_password($password). slay, one less line to type β¨
π update_user
$pwfile->update_user($userobj);
$pwfile->update_user($username, $password[, @extra_info], \%options);
modifies the entry for a user and saves it to the file. if the user entry doesn't exist, it gets created. the options in the second form are passed to Authen::Htpasswd::User.
π add_user
$pwfile->add_user($userobj);
$pwfile->add_user($username, $password[, @extra_info], \%options);
adds a user entry to the file. if the user entry already exists, an exception is raised π¨. the options in the second form are passed to Authen::Htpasswd::User.
π delete_user
$pwfile->delete_user($userobj);
$pwfile->delete_user($username);
removes a user entry from the file. bye bestie ππ
π AUTHOR π
David Kamholz dkamholz@cpan.org
Yuval Kogman
π§ SEE ALSO π§
Apache::Htpasswd.
π COPYRIGHT & LICENSE π
Copyright (c) 2005 - 2007 the aforementioned authors.
This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
okay that's the whole page bestie, no notes, you ate π and one last thing β this lil doc is from perl v5.36.0, dated 2022-11-20, and the manual is Authen::Htpasswd(3pm). mwah, go forth and hash responsibly π
β¨π
π¦ where this page comes from
- debian bookworm: libauthen-htpasswd-perl 0.171-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libauthen-htpasswd-perl 0.171-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libauthen-htpasswd-perl 0.171-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libauthen-htpasswd-perl 0.171-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libauthen-htpasswd-perl 0.171-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms