.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "Htpasswd 3pm" .TH Htpasswd 3pm "2017-09-08" "perl v5.26.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Apache::Htpasswd \- Manage Unix crypt\-style password file. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Apache::Htpasswd; \& \& $foo = new Apache::Htpasswd("path\-to\-file"); \& \& $foo = new Apache::Htpasswd({passwdFile => "path\-to\-file", \& ReadOnly => 1} \& ); \& \& # Add an entry \& $foo\->htpasswd("zog", "password"); \& \& # Change a password \& $foo\->htpasswd("zog", "new\-password", "old\-password"); \& \& # Change a password without checking against old password \& \& $foo\->htpasswd("zog", "new\-password", {\*(Aqoverwrite\*(Aq => 1}); \& \& # Check that a password is correct \& $foo\->htCheckPassword("zog", "password"); \& \& # Fetch an encrypted password \& $foo\->fetchPass("foo"); \& \& # Delete entry \& $foo\->htDelete("foo"); \& \& # If something fails, check error \& $foo\->error; \& \& # Write in the extra info field \& $foo\->writeInfo("login", "info"); \& \& # Get extra info field for a user \& $foo\->fetchInfo("login"); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module comes with a set of methods to use with htaccess password files. These files (and htaccess) are used to do Basic Authentication on a web server. .PP The passwords file is a flat-file with login name and their associated crypted password. You can use this for non-Apache files if you wish, but it was written specifically for .htaccess style files. .SS "\s-1FUNCTIONS\s0" .IX Subsection "FUNCTIONS" .IP "Apache::Htpasswd\->new(...);" 4 .IX Item "Apache::Htpasswd->new(...);" As of version 1.5.4 named params have been added, and it is suggested that you use them from here on out. .Sp .Vb 1 \& Apache::Htpasswd\->new("path\-to\-file"); .Ve .Sp \&\*(L"path-to-file\*(R" should be the path and name of the file containing the login/password information. .Sp .Vb 4 \& Apache::Htpasswd\->new({passwdFile => "path\-to\-file", \& ReadOnly => 1, \& UseMD5 => 1, \& }); .Ve .Sp This is the perferred way to instantiate an object. The 'ReadOnly' param is optional, and will open the file in read-only mode if used. The 'UseMD5' is also optional: it will force \s-1MD5\s0 password under Unix. .Sp If you want to support plain un-encrypted passwords, then you need to set the UsePlain option (this is \s-1NOT\s0 recommended, but might be necessary in some situations) .IP "error;" 4 .IX Item "error;" If a method returns an error, or a method fails, the error can be retrieved by calling \fIerror()\fR .ie n .IP "htCheckPassword(""login"", ""password"");" 4 .el .IP "htCheckPassword(``login'', ``password'');" 4 .IX Item "htCheckPassword(login, password);" Finds if the password is valid for the given login. .Sp Returns 1 if passes. Returns 0 if fails. .ie n .IP "htpasswd(""login"", ""password"");" 4 .el .IP "htpasswd(``login'', ``password'');" 4 .IX Item "htpasswd(login, password);" This will add a new user to the password file. Returns 1 if succeeds. Returns undef on failure. .ie n .IP "htDelete(""login"")" 4 .el .IP "htDelete(``login'')" 4 .IX Item "htDelete(login)" Delete users entry in password file. .Sp Returns 1 on success Returns undef on failure. .ie n .IP "htpasswd(""login"", ""new-password"", ""old-password"");" 4 .el .IP "htpasswd(``login'', ``new-password'', ``old-password'');" 4 .IX Item "htpasswd(login, new-password, old-password);" If the \fIold-password\fR matches the \fIlogin's\fR password, then it will replace it with \fInew-password\fR. If the \fIold-password\fR is not correct, will return 0. .ie n .IP "htpasswd(""login"", ""new-password"", {'overwrite' => 1});" 4 .el .IP "htpasswd(``login'', ``new-password'', {'overwrite' => 1});" 4 .IX Item "htpasswd(login, new-password, {'overwrite' => 1});" Will replace the password for the login. This will force the password to be changed. It does no verification of old-passwords. .Sp Returns 1 if succeeds Returns undef if fails .ie n .IP "fetchPass(""login"");" 4 .el .IP "fetchPass(``login'');" 4 .IX Item "fetchPass(login);" Returns \fIencrypted\fR password if succeeds. Returns 0 if login is invalid. Returns undef otherwise. .ie n .IP "fetchInfo(""login"");" 4 .el .IP "fetchInfo(``login'');" 4 .IX Item "fetchInfo(login);" Returns additional information if succeeds. Returns 0 if login is invalid. Returns undef otherwise. .IP "\fIfetchUsers()\fR;" 4 .IX Item "fetchUsers();" Will return either a list of all the user names, or a count of all the users. .Sp The following will return a list: my \f(CW@users\fR = \f(CW$Htpasswd\fR\->\fIfetchUsers()\fR; .Sp The following will return the count: my \f(CW$user_count\fR = \f(CW$Htpasswd\fR\->\fIfetchUsers()\fR; .ie n .IP "writeInfo(""login"", ""info"");" 4 .el .IP "writeInfo(``login'', ``info'');" 4 .IX Item "writeInfo(login, info);" Will replace the additional information for the login. Returns 0 if login is invalid. Returns undef otherwise. .ie n .IP "CryptPasswd(""password"", ""salt"");" 4 .el .IP "CryptPasswd(``password'', ``salt'');" 4 .IX Item "CryptPasswd(password, salt);" Will return an encrypted password using 'crypt'. If \fIsalt\fR is omitted, a salt will be created. .SH "INSTALLATION" .IX Header "INSTALLATION" You install Apache::Htpasswd, as you would install any perl module library, by running these commands: .PP .Vb 5 \& perl Makefile.PL \& make \& make test \& make install \& make clean .Ve .PP If you are going to use \s-1MD5\s0 encrypted passwords, you need to install Crypt::PasswdMD5. .PP If you need to support \s-1SHA1\s0 encrypted passwords, you need to install Digest::SHA and MIME::Base64. .SH "DOCUMENTATION" .IX Header "DOCUMENTATION" \&\s-1POD\s0 style documentation is included in the module. These are normally converted to manual pages and installed as part of the \*(L"make install\*(R" process. You should also be able to use the 'perldoc' utility to extract and read documentation from the module files directly. .SH "AVAILABILITY" .IX Header "AVAILABILITY" The latest version of Apache::Htpasswd should always be available from: .PP .Vb 1 \& $CPAN/modules/by\-authors/id/K/KM/KMELTZ/ .Ve .PP Visit to find a \s-1CPAN\s0 site near you. .SH "CHANGES" .IX Header "CHANGES" Revision 1.9.0 \s-1SHA\s0 dependency changes .PP Revision 1.8.0 Added proper \s-1PREREQ_PM\s0 .PP Revision 1.7.0 Handle \s-1SHA1\s0 and plaintext. Also change the interface for allowing change of password without first checking old password. \s-1IF YOU DON\s0'T \s-1READ THE DOCS AND SEE I DID THIS DON\s0'T \s-1EMAIL ME\s0! .PP Revision 1.6.0 Handle Blowfish hashes when that's the mechanism \fIcrypt()\fR uses. .PP Revision 1.5.9 \s-1MD5\s0 for *nix with new UseMD5 arg for \fInew()\fR .PP Revision 1.5.8 Bugfix to \fIhtpasswd()\fR. .PP Revision 1.5.7 \s-1MD5\s0 for Windows, and other minor changes. .PP Revision 1.5.6 Minor enhancements. .PP Revision 1.5.5 2002/08/14 11:27:05 Newline issue fixed for certain conditions. .PP Revision 1.5.4 2002/07/26 12:17:43 kevin doc fixes, new fetchUsers method, new ReadOnly option, named params for \fInew()\fR, various others .PP Revision 1.5.3 2001/05/02 08:21:18 kevin Minor bugfix .PP Revision 1.5.2 2001/04/03 09:14:57 kevin Really fixed newline problem :) .PP Revision 1.5.1 2001/03/26 08:25:38 kevin Fixed another newline problem .PP Revision 1.5 2001/03/15 01:50:12 kevin Fixed bug to remove newlines .PP Revision 1.4 2001/02/23 08:23:46 kevin Added support for extra info fields .PP Revision 1.3 2000/04/04 15:00:15 meltzek Made file locking safer to avoid race conditions. Fixed typo in docs. .PP Revision 1.2 1999/01/28 22:43:45 meltzek Added slightly more verbose error croaks. Made sure error from htCheckPassword is only called when called directly, and not by \f(CW$self\fR. .PP Revision 1.1 1998/10/22 03:12:08 meltzek Slightly changed how files lock. Made more use out of carp and croak. Made sure there were no ^M's as per Randal Schwartz's request. .SH "BUGS" .IX Header "BUGS" None known at time of writing. .SH "AUTHOR INFORMATION" .IX Header "AUTHOR INFORMATION" Copyright 1998..2005, Kevin Meltzer. All rights reserved. It may be used and modified freely, but I do request that this copyright notice remain attached to the file. You may modify this module as you wish, but if you redistribute a modified version, please attach a note listing the modifications you have made. .PP This is released under the same terms as Perl itself. .PP Address bug reports and comments to: kmeltz@cpan.org .PP The author makes no warranties, promises, or guarantees of this software. As with all software, use at your own risk. .SH "SEE ALSO" .IX Header "SEE ALSO" Apache::Htgroup, Crypt::PasswdMD5, Digest::SHA, MIME::Base64