?
Solved

add a new user to .htaccess file

Posted on 1997-06-23
3
Medium Priority
?
1,632 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
[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
  • 2
3 Comments
 

Accepted Solution

by:
gracie earned 200 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

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Six Sigma Control Plans
Suggested Courses

771 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