Authen...::User(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::User πŸ’–

okay so bestie, this is a page from the User Contributed Perl Documentation, and it's literally about Authen::Htpasswd::User β€” which is the lil' object that represents one single user line inside a .htpasswd file. that's it, that's the whole vibe. one user, one line, so much power. πŸŽ€


✨ NAME ✨

Authen::Htpasswd::User β€” represents a user line in a .htpasswd file 🫢


🌸 SYNOPSIS 🌸

my $user = Authen::Htpasswd::User->new($username, $password[, @extra_info], \%options);
my $user = $pwfile->lookup_user($username); # from Authen::Htpasswd object

if ($user->check_password($password)) { ... }
if ($user->hashed_password eq $foo) { ... }

# these are written immediately if the user was looked up from an Authen::Htpasswd object
$user->username('bill');
$user->password('bar');
$user->hashed_password('tIYAwma5mxexA');
$user->extra_info('root', 'joe@site.com', 'Joe Sysadmin');
$user->set(username => 'bill', password => 'foo'); # set several at once

print $user->to_line, "\n";

like… look at that. it's giving object-oriented elegance. no cap. ✨


πŸ¦‹ METHODS πŸ¦‹

πŸ’… new

my $userobj = Authen::Htpasswd::User->new($username, $password[, @extra_info], \%options);

this is the birth of a user object. iconic. πŸ‘‘

you can also hand over the args and options all mushed together in one hash, like this:

{ username => $foo, password => $bar, extra_info => [$email, $name], ... }

so whichever way you like to feed it, it's fed. πŸ’–

πŸ” encrypt_hash

πŸ” check_hashes

okay so these two? go read Authen::Htpasswd. that's where they live. ✨

πŸ” hashed_password

this one explicitly sets the value of the hashed password, instead of generating it for you via password. like, you already did the math, bestie, so here's the answer. πŸ’…

😭 check_password

$userobj->check_password($password,\@check_hashes);

returns whether the password matches or not. that's it. yes/no. slay or no slay.

check_hashes works exactly the same as it does for Authen::Htpasswd, iykyk.

πŸŽ€ username

πŸŽ€ hashed_password

πŸŽ€ extra_info(@fields)

get and set the fields of the user line. these three, plus password and set down below, write any changes immediately if the user was looked up from an Authen::Htpasswd object. so like, no "save" button. it's instant. main character energy fr fr.

⚠️ and if you change the username? the old entry is NOT preserved. it's gone. ghosted. πŸ’€

πŸ“ password

$userobj->password($newpass);

encrypts a new password for you. πŸ’–

⚠️ heads up bestie: it DIES if $newpass is not provided. so like, actually pass the password. πŸ™ˆ

⭐ set

$userobj->set(item => $value, ...);

sets any of the four values above all at once. and the cute part? if the file is gonna be written, it only writes it once. efficiency queen. πŸ‘‘

🌈 to_line

$userobj->to_line;

returns a line for the user that's suitable for printing straight into a .htpasswd file.

⚠️ there is no newline at the end. so if you want one, add it yourself. the SYNOPSIS up top shows you how. 🫢

πŸ‘‘ AUTHOR πŸ‘‘

David Kamholz dkamholz@cpan.org

Yuval Kogman


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, we ate and left no crumbs. πŸ“βœ¨ this lil' slice of wisdom was cooked up on 2022-11-20 and ships with perl v5.36.0. mwah, go write some .htpasswd files responsibly. πŸ’…πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from