Solved

usernames/passwords

Posted on 1998-07-19
2
242 Views
Last Modified: 2010-03-18
I am using Red Hat Linux 5.1 and Apache.  I have created a "users" file and I need to create many usernames/passwords for a members area on my web site.  Is there any way to speed up the process instead of having to use the "htpasswd /some/directory/users" command?  This seems to be very tedious and time consuming, considering the fact that I have to make a list of about 1,000 usernames/passwords.  Any "automated" ways of doing this?  Thanks.
0
Comment
Question by:TJWin
2 Comments
 
LVL 2

Expert Comment

by:JYoungman
ID: 1585525
You could use expect (comes with Tcl).   It's a good way of automating "interactive" programs.   It's on the RH CD in the "expect" package.

0
 
LVL 2

Accepted Solution

by:
alexbik earned 20 total points
ID: 1585526
This perl script generates a .htacces and .htpassword for you from a file called users:
Make sure the 'users' file is removed afterwards! Het file should look like:
user:pass
user2:pass2

and so on..

#!/usr/bin/perl
$cwd = qx/pwd/;
chop $cwd;

srand(time || $$);
@cryptchars = (a..z,A..Z,0..9);
open (USERS,"users") || die "Error opening file \"users\"\n";
while ($line = <USERS>) {
  while ($line =~ /[\n|\r| ]$/) {chop $line}
  if ($line =~ /^(.+):(.+)$/) {
    ($username,$password) = split /:/,$line;
    $pass{$username} = $password;
  }
}
close USERS;

open (PWF,">.htpasswd") || die "Error opening file \".htpasswd\" for writing\n";
foreach $user (sort keys %pass) {
  $cc = $cryptchars[rand($#cryptchars)].$cryptchars[rand($#cryptchars)];
  $cryptpass = crypt($pass{$user},$cc);
  print PWF "$user:$cryptpass\n";
}
close PWF;

if (! -e ".htaccess") {
  open (ACC,">.htaccess") || die "Error opening file \".htaccess\" for writing\n";
  print ACC "AuthUserFile $cwd/.htpasswd\n";
  print ACC "AuthName users\n";
  print ACC "AuthType Basic\n";
  print ACC "require valid-user\n";
  close ACC;
}

exit;
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 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

15 Experts available now in Live!

Get 1:1 Help Now