Solved

usernames/passwords

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

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

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

Suggested Solutions

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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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