• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

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

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
mmcw
Asked:
mmcw
  • 6
  • 3
1 Solution
 
kistlerCommented:
Make a script yourself:-)
with crypt($pw,$salt) you can crypt the
pw and feed in into the other file.
Per.
0
 
ThomyCommented:
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
 
mmcwAuthor Commented:
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
mmcwAuthor Commented:
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
 
mmcwAuthor Commented:
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
 
ThomyCommented:
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
 
mmcwAuthor Commented:
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
 
mmcwAuthor Commented:
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
 
ThomyCommented:
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
 
mmcwAuthor Commented:
Thank you for your help
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now