Solved

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

Posted on 1999-01-17
10
221 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
  • 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
 

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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

705 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

17 Experts available now in Live!

Get 1:1 Help Now