Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

usernames/passwords

Posted on 1998-07-19
2
Medium Priority
?
270 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 80 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

719 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