Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Apache::Htpasswd syntax questions

by thatguy (Parson)
on Aug 04, 2001 at 08:34 UTC ( [id://102209]=note: print w/replies, xml ) Need Help??


in reply to Apache::Htpasswd syntax questions

what's the problem you're having? also, i would suggest using CGI.pm as it will make the forms and mundane html easier.

Update: Apache::Htpasswd is sweet! I had been writing htpasswd the old caveman way.. with crypt. This module makes things very nice.. oh and here's a little something that uses Apache::Htpasswd and CGI

#!/usr/bin/perl -wT use CGI qw(standard); use CGI::Carp qw(fatalsToBrowser); use Apache::Htpasswd; my $htpasswd="htpasswd"; my $main=new CGI(); print $main->header; print $main->start_html('Password Administration'); $main->import_names('Q'); if ($Q::form) { if (($Q::username) && ($Q::oldpass) && ($Q::newpass)) { # all the forms have been entered &change_pass } else { print "please fill in all fields"; } } else { # must be a first time customer print $main->startform; print "<table border=0 cellpadding=1 cellspacing=0>\n"; print "<tr><td>Username: </td><td>",$main->textfield(-name=>'u +sername',-size=>30),"</td></tr>"; print "<tr><td>Password: </td><td>",$main->password_field(-nam +e=>'oldpass',-size=>30),"</td></tr>"; print "<tr><td>New Password: </td><td>",$main->password_field( +-name=>'newpass',-size=>30),"</td></tr>"; print "<tr><td>&nbsp;</td><td>",$main->submit(-name=>'form',-v +alue=>'Change Password'),"</td></tr></tab le>"; } sub change_pass { if (-e $htpasswd) { # if the htpasswd file exists my $htpass = new Apache::Htpasswd("$htpasswd"); # use Apache::Htpasswd's builtin function to verify old pass befor +e changing $htpass->htpasswd($Q::username,$Q::newpass,$Q::oldpass +); # get errors (if any) my $err=$htpass->error; if ($err) { print "Error. Most likely due to an inccorect +password or username \n"; } else { ## must be no errors print "user $Q::username password changed\n"; } } else { print "$htpasswd cannot be found\n"; } }

-p

Replies are listed 'Best First'.
Re: Re: Apache::Htpasswd syntax questions
by KM (Priest) on Aug 04, 2001 at 22:05 UTC
    Glad you like it! I think I (still) have a newline issue in the code somewhere but haven't had the tuits to fix it yet. If you have any problems with newlines, send me some example code (email in the POD) and it may prod me to find tuits :)

    Cheers,
    KM

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://102209]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-19 04:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found