?
Solved

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

Posted on 1999-01-17
10
Medium Priority
?
232 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 300 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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

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