Solved

access with .htpasswd file

Posted on 1998-02-26
6
275 Views
Last Modified: 2013-12-25
I have a website that has .htpasswd file in it, I need a program that can add to the .htpasswd file and send me an email with other information.  Does anyone know of a program like this?
0
Comment
Question by:CYO
  • 3
  • 2
6 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 1832045
You web server should have included a program for putting entries in the .htpasswd file.  For example, APACHE includes a utility called (strangely enough) htpasswd.
0
 

Author Comment

by:CYO
ID: 1832046
i have a program that I manual can do this put I would like to do it automaticly.
0
 

Expert Comment

by:manningc
ID: 1832047
You can write a perl script to execute the password utility,
using the 'system' function in perl.  That is, if the
password utility can accept command-line arguments or
input from STDIN.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:CYO
ID: 1832048
There was a cgi program that wrote to the .htpasswd file and I was wondering if anyone know where can I get it again.
0
 

Accepted Solution

by:
manningc earned 50 total points
ID: 1832049
I found the following below by searching the newsgroups:

If you want a simple perl program which encrypts and stores
name:password pairs in htpasswd format just use this.
(This snippet assumes you've already obtained the name:password pair in clear text, either by assigning them manually in the source, or by obtaining them from a web form)


====Snip

# Generate a pseudo-random two digit salt
# The while loop ensures that the random number chosen
# corresponds to a printable ascii value. [0-9a-zA-Z]
$salt = "";
@TmpPW  = ();
srand (time);
for ($i = 0; $i < 2 ; $i++) {
    $x = 0;
    while ($x eq 0) {
        $x = rand() * 200;
        if ($x < 48) { $x = 0; }
        if ($x > 57 && $x < 65) { $x = 0; }
        if ($x > 90 && $x < 97) { $x = 0; }
        if ($x > 122) { $x = 0; }
    }
    $tmp = sprintf("%c", $x);
    push (@TmpPW, $tmp);
}
$salt = join("", @TmpPW);

# Now encrypt the entered password using the pseudo-random salt
# Users clear text password is stored in $password

$pwd = crypt($password, $salt);
$line=join(':',$username,$pwd);

=====End Snip

From here, you could open the .htpasswd file in append
mode and and write the
line into it.  The only unsure thing here is what 'salt' the
web server expects when it compares the user-entered password
to the entry in the file.  If it takes the entry in the
file, uses the 'salt' (first two bytes of the encrypted pwd)
to encrypt the user-entered password, and then compares the
result, it should work.  Of course, you need to also deal with
file-locking issues so that two concurrent users don't wipe
each other out.

Frankly, you'd be better off to programmatically invoke the
htpasswd or similar utility to do this for you, since these
routines are completely stable and debugged.  Go to Yahoo
and search for htpasswd.c to get compilable source code for
this utility.  

0
 

Author Comment

by:CYO
ID: 1832050
sorry it took me so long to get back with you.
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question