Solved

add a new user to .htaccess file

Posted on 1997-06-23
3
1,604 Views
Last Modified: 2012-06-22
I need to add a user to .htpasswd and .htaccess file this is what I got so far.

#!/usr/bin/perl
##############################################################################
#user adding program  v1.0
#
#By: Chris Allen
#
#This program will add a user to a .htpasswd file and a .htaccess file
#
##########################################################################

#set variables
$path_to_htpasswd="/opt2/home4/cyo/access/.htpasswd"
$path_to_htaccess="/opt2/home4/cyo/public_html/members/.htaccess"



# adding user to htpasswd file


             #first, read the existing htpasswd file into memory
             open (HTFILE, "<$path_to_htpasswd")
             || die "Can't read htpasswd file - $!";
             while (<HTFILE>) {
               chomp ($_);
               ($htuser, $htcpass) = split (/:/);
               $ht{$htuser} = $htcpass;
             } close (HTFILE);

             #next, you've already read user's form input, and
             #$newuser and $newpasswd are set to the appropriate
             values

             $salt = substr ("$$", 0, 2); #or, make a more random
             salt...
             $ht{$newuser} = crypt ($newuser, $salt);

             #last, write the new htpasswd file.
             # this is the part that is most error-prone
             # you might want to write to a temporary file,
             # then replace the old file.
             # I'm just going to overwrite the old file

             unlink ("$path_to_htpasswd"); # delete
             old file
             open (HTFILE, ">")
             || die "Can't write file - $!";
             while (($htuser, $htcpass) = each (%ht)) {
               print HTFILE "$htuser:$htcpass\n");
             }
             close (HTFILE);



# add user to .htaccess





All I need is how to add user to .htaccess file
0
Comment
Question by:CYO
  • 2
3 Comments
 

Accepted Solution

by:
gracie earned 100 total points
ID: 1204339
You actually don't.  .htaccess just points to .htpassword
It can also point to a group file ( .htgroup )

Here's what the contents look like:

AuthUserFile /www/admin/.htpasswd
AuthGroupFile /www/admin/.htgroup
AuthName Administration
AuthType Basic

<Limit GET POST PUT>
require group auth
</Limit>

So, once .htaccess is setup, you don't need to modify it for each user.

Enjoy,
Gracie
0
 

Author Comment

by:CYO
ID: 1204340
Do I need to add the user to .htgroup? how?
0
 

Expert Comment

by:gracie
ID: 1204341
I'm not sure it's required (just delete that line from .htaccess).

If you find that it is required or if you want it anyway...
it's just a text file.  Here's what it looks like:
~~~~~~~~~~~~~~~~~~~~
auth: sally
auth: tom
~~~~~~~~~~~~~~~~~~~~
So, you would just add the following for each new user:
auth: newuser

Take Care,
Gracie
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

733 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