• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

lib/Authen/H09-Aug-2011-631303

t/H09-Aug-2011-157103

ChangesH A D09-Aug-20111.5 KiB4030

MANIFESTH A D09-Aug-2011382 1615

META.jsonH A D09-Aug-20111 KiB4746

META.ymlH A D09-Aug-2011617 2827

Makefile.PLH A D09-Aug-2011638 2319

READMEH A D09-Aug-20113.4 KiB10073

README

1NAME
2    Authen::Htpasswd - interface to read and modify Apache .htpasswd files
3
4SYNOPSIS
5        my $pwfile = Authen::Htpasswd->new('user.txt', { encrypt_hash => 'md5' });
6
7        # authenticate a user (checks all hash methods by default)
8        if ($pwfile->check_user_password('bob', 'foo')) { ... }
9
10        # modify the file (writes immediately)
11        $pwfile->update_user('bob', $password, $info);
12        $pwfile->add_user('jim', $password);
13        $pwfile->delete_user('jim');
14
15        # get user objects tied to a file
16        my $user = $pwfile->lookup_user('bob');
17        if ($user->check_password('vroom', [qw/ md5 sha1 /])) { ... } # only use secure hashes
18        $user->password('foo'); # writes to file
19        $user->set(password => 'bar', extra_info => 'editor'); # change more than one thing at once
20
21        # or manage the file yourself
22        my $user = Authen::Htpasswd::User->new('bill', { hashed_password => 'iQ.IuWbUIhlPE' });
23        my $user = Authen::Htpasswd::User->new('bill', 'bar', 'staff', { encrypt_hash => 'crypt' });
24        print PASSWD $user->to_line, "\n";
25
26DESCRIPTION
27    This module provides a convenient, object-oriented interface to
28    Apache-style .htpasswd files. It supports passwords encrypted via MD5,
29    SHA1, and crypt, as well as plain (cleartext) passwords. It requires
30    Crypt::PasswdMD5 for MD5 and Digest::SHA1 for SHA1. Additional fields
31    after username and password, if present, are accessible via the
32    "extra_info" array.
33
34METHODS
35  new
36        my $pwfile = Authen::Htpasswd->new($filename, \%options);
37
38    Creates an object for a given .htpasswd file. Options:
39
40    encrypt_hash
41        How passwords should be encrypted if a user is added or changed.
42        Valid values are "md5", "sha1", "crypt", and "plain". Default is
43        "crypt".
44
45    check_hashes
46        An array of hash methods to try when checking a password. The
47        methods will be tried in the order given. Default is "md5", "sha1",
48        "crypt", "plain".
49
50  lookup_user
51        my $userobj = $pwfile->lookup_user($username);
52
53    Returns an Authen::Htpasswd::User object for the given user in the
54    password file.
55
56  all_users
57        my @users = $pwfile->all_users;
58
59  check_user_password
60        $pwfile->check_user_password($username,$password);
61
62    Returns whether the password is valid. Shortcut for
63    "$pwfile->lookup_user($username)->check_password($password)".
64
65  update_user
66        $pwfile->update_user($userobj);
67        $pwfile->update_user($username, $password[, @extra_info], \%options);
68
69    Modifies the entry for a user saves it to the file. If the user entry
70    does not exist, it is created. The options in the second form are passed
71    to Authen::Htpasswd::User.
72
73  add_user
74        $pwfile->add_user($userobj);
75        $pwfile->add_user($username, $password[, @extra_info], \%options);
76
77    Adds a user entry to the file. If the user entry already exists, an
78    exception is raised. The options in the second form are passed to
79    Authen::Htpasswd::User.
80
81  delete_user
82        $pwfile->delete_user($userobj);
83        $pwfile->delete_user($username);
84
85    Removes a user entry from the file.
86
87AUTHOR
88    David Kamholz "dkamholz@cpan.org"
89
90    Yuval Kogman
91
92SEE ALSO
93    Apache::Htpasswd.
94
95COPYRIGHT & LICENSE
96            Copyright (c) 2005 the aforementioned authors. All rights
97            reserved. This program is free software; you can redistribute
98            it and/or modify it under the same terms as Perl itself.
99
100