Solved

access with .htpasswd file

Posted on 1998-02-26
6
273 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now