2013-05-15 11:55:06 +01:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
#
|
|
|
|
# Usage: htpasswd.pl [encrypted_password]
|
|
|
|
#
|
|
|
|
# If no arguments are given then it will ask for a password and will show its
|
|
|
|
# encrypted form to be saved on a file.
|
|
|
|
#
|
|
|
|
# If the argument is an encrypted password it will ask the password and will
|
|
|
|
# verify if it's valid.
|
|
|
|
#
|
2015-01-07 16:21:56 +00:00
|
|
|
# WARNING: don't use the character colon ':' as part of your name or password
|
|
|
|
# since this character is used as field separator.
|
|
|
|
#
|
2013-05-15 11:55:06 +01:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
my $word;
|
|
|
|
|
|
|
|
if(!$ARGV[0]) {
|
|
|
|
my $salt = join('', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]);
|
|
|
|
print "Password to encrypt: ";
|
2018-03-05 15:39:52 +00:00
|
|
|
system("stty -echo");
|
2013-05-15 11:55:06 +01:00
|
|
|
chomp($word = <STDIN>);
|
2018-03-05 15:39:52 +00:00
|
|
|
system("stty echo");
|
2013-05-15 11:55:06 +01:00
|
|
|
print crypt($word, $salt) . "\n";
|
|
|
|
} else {
|
|
|
|
system("stty -echo");
|
|
|
|
print "Password: ";
|
|
|
|
chomp($word = <STDIN>);
|
|
|
|
system("stty echo");
|
|
|
|
print "\n";
|
|
|
|
die "Sorry, do not match.\n" if crypt($word, $ARGV[0]) ne $ARGV[0];
|
|
|
|
print "Ok!\n";
|
|
|
|
}
|
|
|
|
|