Solved

access with .htpasswd file

Posted on 1998-02-26
6
267 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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 to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Ever wondered how to display how many visitors you have online. In this tutorial I will show you an easy but effective way to display the number of online visitors in WhizBase. In this article I assume you have read my previous articles and know …
Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

743 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

12 Experts available now in Live!

Get 1:1 Help Now