Solved

usernames/passwords

Posted on 1998-07-19
2
251 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SFP configuration on a Linux server 8 217
Unix / Linux grid computing 5 163
best simple nfs export and fstab commands for basic sharing? 3 81
Issue to mail 11 110
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

821 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