Using CGI.pm lets us drop the somewhat-broken parseform() altogether, making the entire program much shorter. Doing that also lets us have somewhat nicer error checking. The warnings you mention earlier have to do with form values not being present. Here's a potential fix:
#!/usr/bin/perl -w use strict; use CGI; use Apache::Htpasswd; my $htpasswd = "/etc/htsec/motion.ht"; my $method = Apache::Htpasswd->new($htpasswd); my $q = CGI->new(); my %fields; for my $field (qw( username newpw oldpw )) { $fields{$field} = $q->param($field); unless (defined($fields{$field})) { showform(); exit(); } } $method->htpasswd(@fields{ qw(username newpw oldpw) }); # print a success message sub showform { my $q = shift; print $q->header(); print <<HTML; <html> <head><title>Password Administration</title></head> <body bgcolor="#FFFFFF"> <form method = "post" action = "https://www.lunarmedia.net/motion/chpa +ss.cgi"> Username:&nbsp;<input type="text" length="30" name="username"><br> Password:&nbsp;<input type="password" length="30" name="oldpw"><br> New Password:&nbsp;<input type="password" length="30" name="newpw"><br +> <input type="submit" value="Go!"><br> </body> </html> HTML }
This allows us to verify that each field contains a defined value, aborting if necessary.

Using CGI to generate the HTML would also give you the benefit of sticky form fields, where the contents of the field display on subsequent invocations.

Update: Fixed two typos. The code ought to work now. Then a third, as c pointed out.


In reply to Re: Apache::Htpasswd syntax questions by chromatic
in thread Apache::Htpasswd syntax questions by c

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.