Solved

usernames/passwords

Posted on 1998-07-19
2
239 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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

11 Experts available now in Live!

Get 1:1 Help Now