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

Posted on in Categories Web Server last updated October 6, 2008

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:

Now you can create htpasswd file for lighttpd or nginx:

Perl script to replace htpasswd

5 comment

  1. Thanks, this article and the anon comment inspired me to take it a step further:

    This is now super easy to use and it will always append the record to the file. Enjoy!

  2. Thanks, this article and the anon comment inspired me to take it a step further:

    This is now super easy to use and it will always append the record to the file. Enjoy!

  3. I use this script:

    #!/usr/bin/perl
    use strict;
    chomp(my $username=$ARGV[0]);
    chomp(my $password=$ARGV[1]);
    print $username.":".crypt($password,$username)."\n";

    In this script $password – main string for password generation, and $username – salt.
    You can use it like that:

    ./htpasswd.pl user password > .htpasswd
    cat .htpasswd
    user:usjRS48E8ZADM

Leave a Comment