≡ Menu

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

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 comments… add one }
  • Fleshgrinder March 28, 2012, 7:36 pm

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

    #!/usr/bin/perl
    use strict;
    chomp(my $filename=$ARGV[0]);
    chomp(my $username=$ARGV[1]);
    chomp(my $password=$ARGV[2]);
    if (!$filename || !$username || !$password) {
      print "USAGE: ./crypt.pl filename username password\n\n";
    } else {
      open FILE, ">>", $filename or die $!;
      print FILE $username . ":" . crypt($password, $username) . "\n";
      close FILE or die $!;
    }

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

    • Vivek Gite April 6, 2012, 6:03 pm

      Thanks for sharing updated version :)

  • Fleshgrinder March 28, 2012, 7:32 pm

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

    #!/usr/bin/perl
    use strict;
    chomp(my $filename=$ARGV[0]);
    chomp(my $username=$ARGV[1]);
    chomp(my $password=$ARGV[2]);
    if ($filename == '' || $username == '' || $password == '') {
      print "USAGE: ./crypt.pl filename username password\n\n";
    } else {
      open FILE, ">>", $filename or die $!;
      print FILE $username . ":" . crypt($password, $username) . "\n";
      close FILE or die $!;
    }
    

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

  • anonymous September 7, 2010, 3:22 pm

    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

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

    Thank you very much for this one. Worked perfectly.

Security: Are you a robot or human?

Leave a Comment