Authen::Htpasswd(3pm)

πŸ“¦
version 0.171 Β· 2 versions
  • 0.171 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.171 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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 (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