Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

access with .htpasswd file

Posted on 1998-02-26
6
Medium Priority
?
286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

 

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 100 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 Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
The viewer will learn how to dynamically set the form action using jQuery.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

688 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