Solved

access with .htpasswd file

Posted on 1998-02-26
6
277 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 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.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
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…
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…
The viewer will learn how to count occurrences of each item in an array.

752 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