Solved

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

Posted on 1999-01-17
10
222 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Bash one liner, start and end time calculation 13 103
Replace  text in a file 2 97
Perl modules on linux ec2 3 96
Put query string from URL request -  PERL HTTP Daemon 2 73
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…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

920 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

14 Experts available now in Live!

Get 1:1 Help Now