Solved

Multiple editing .htpasswd file (Using a pass.txt file)

Posted on 1999-01-17
10
228 Views
Last Modified: 2012-06-27
I am looking for an perl script that can be used to edit the htpasswd file. I want to use a input file where the user name and password are seperated by a space. (pass.txt)
The script must reed the user name and password and automatic place them into the htpasswd file.
I know how to do it one by one, but I have about 2000 user names.

Does anyone know a script that can do this??

greeting Michel Weegerink
Email:mmcw@worldonline.nl
0
Comment
Question by:mmcw
[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
  • 6
  • 3
10 Comments
 

Expert Comment

by:kistler
ID: 1210167
Make a script yourself:-)
with crypt($pw,$salt) you can crypt the
pw and feed in into the other file.
Per.
0
 

Accepted Solution

by:
Thomy earned 100 total points
ID: 1210168
I assume you're using Apache on a Unix-Box and you have a file like the following
pass.txt:
thomas geheim
hallo test
fritz figaro
henry mueller

then you can use the following script to make a password-file:

#!/usr/bin/perl
# file pw.pl

@chars = (a .. z, A .. Z, 0 .. 9);
while (<>) {
      chomp;
      ($userid, $pass) = split(/ /);
      $salt = $chars[rand(61)].$chars[rand(61)];
      $pstr = crypt($pass, $salt);
      print($userid, ':', $pstr, "\n");
}

# perl pw.pl pass.txt > users
# cat users
thomas:Ezuq4WIGrrM5w
hallo:2ES7eMaRBSzFk
fritz:QFjLs0p4UQF0.
henry:cIVm9w4g6uf/Q

Thomy

0
 

Author Comment

by:mmcw
ID: 1210169
Could you mail me the script by email. Can it be used from a par example a netscape browser.
I am not an perl expert!!!

My email adres is: mmcw@worldonline.nl

greetings Michel
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mmcw
ID: 1210170
Isn't it possble to make teh script work from a browser.

It isn't possible to use the script of a tellnet session!!
Don't ask me why. Maybe because it is a demon server!!
I have asked the demon provider but till now without an answer!!
Script of a webbrowser will work fine.

greetings Michel
0
 

Author Comment

by:mmcw
ID: 1210171
Sorry very bad english!1

Isn't it possble to make the script work from a browser.

It isn't possible to use the script of a tellnet session!!
Don't ask me why. Maybe because it is a demon server!!
I have asked the demon provider but till now without an answer!!
A script started of a webbrowser will work fine.

greetings Michel
0
 

Expert Comment

by:Thomy
ID: 1210172
No isn't!!

There is no webbrowser with build in perl interpreter. You need a perl interpreter, no webbrowser. There are also a perl interpreter for Macintosh or Win32. You can probably try to download a such one and run the script manually.
I don't know why but my perl interpreter running on Win NT doesn't support the function 'crypt'. But that is port dependend. On Linux everything works fine.

Thomy
0
 

Author Comment

by:mmcw
ID: 1210173
But i don't want to use the browser for using the perl interpreter, but only to use to start the perl script where the first line will tell the script where the perl interpreter is!!
I believe the demon server has the perl interpreter hidden for use with the tellnet session. For script, like a counter, strated from a browser the perl interpreter works fine (Like a counter axs)
That why I want to use the browser. Only for using to start the script!!
The output (if possible) to the .htpasswd file or to the browsers screen

greetings Michel
0
 

Author Comment

by:mmcw
ID: 1210174
But i don't want to use the browser for using the perl interpreter, but only to use to start the perl script where the first line will tell the script where the perl interpreter is!!
I believe the demon server has the perl interpreter hidden for use with the tellnet session. For script, like a counter, strated from a browser the perl interpreter works fine (Like a counter axs)
That why I want to use the browser. Only for using to start the script!!
The output (if possible) to the .htpasswd file or to the browsers screen

greetings Michel
0
 

Expert Comment

by:Thomy
ID: 1210175
OK, you could make a html-page with a form including a multiline textarea ie. called "in". Then you can user CGI.pm to decode the query-string submittet from your browser process it and write the output back to the browser.
You have to copy your textfile into this area and start this script. Then save the output in a new textfile called .htaccess.

#!/usr/bin/perl
use CGI qw/:standard/;
unless (param('in')) {
  print header, start_html("Error"), p("No data was found"), end_html;
  exit(1);
}

$input = param('in');
@lines = split(/\n/, $input);
print header('text/plain');
@chars = (a .. z, A .. Z, 0 .. 9);
foreach (@lines) {
($userid, $pass) = split(/ /);
$salt = $chars[rand(61)].$chars[rand(61)];
$pstr = crypt($pass, $salt);
print($userid, ':', $pstr, "\n");
}

Thomy
0
 

Author Comment

by:mmcw
ID: 1210176
Thank you for your help
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

624 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