htpasswd Replacement: Perl Script To Create Password Using crypt()

in Web Server

Webserver such as Nginx / Lighttpd accepets passwords using encoded method i.e. function crypt(3) is needs. You can create the password file with the htpasswd program from Apache. Sometime Apache is not installed use the following perl script to create password.

How do I use crypt.pl?

Download script

Set permissions:
chmod +x crypt.pl
./crypt.pl mySecrete

Sample Output:

$1$mySecret$TQgDKW6xpDmEUyxm5ZDxv/

Now you can create htpasswd file for lighttpd or nginx:

user:$1$mySecret$TQgDKW6xpDmEUyxm5ZDxv/

Perl script to replace htpasswd

#!/usr/bin/perl
use strict;
 
my $passWord=$ARGV[0];
print crypt($passWord,$passWord)."\n";
Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our email newsletter to make sure you don't miss a single tip/tricks.

{ 1 comment… read it below or add one }

Hans-Gunther Schmidt May 27, 2009 at 4:07 pm

Thank you very much for this one. Worked perfectly.

Reply

Leave a Comment

Previous post: Shell Script To Start FastCGI PHP Server For Nginx Web Server

Next post: Apache FastCGI / mod_fastcgi PHP Script