Created
May 17, 2012 04:39
-
-
Save taiyoh/2716408 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Getopt::Long; | |
use Apache::Htpasswd; | |
use Term::ReadKey; | |
my $create; | |
my $result = GetOptions("create|c" => \$create); | |
my $path = shift or die "require file path\n"; | |
my $user = shift or die "require auth user\n"; | |
unlink $path if -f $path && $create; | |
unless (-f $path) { | |
open my $h, '>', $path; | |
close $h; | |
} | |
my $htpass = Apache::Htpasswd->new($path); | |
print "New password: "; | |
ReadMode 'noecho'; | |
my $pass1 = ReadLine(0); | |
chomp $pass1; $pass1 =~ s{[\r\n]}{}g; | |
ReadMode 'restore'; | |
print "\n"; | |
print "Re-type New password: "; | |
ReadMode 'noecho'; | |
my $pass2 = ReadLine(0); | |
chomp $pass2; $pass2 =~ s{[\r\n]}{}g; | |
ReadMode 'restore'; | |
print "\n"; | |
if ($pass1 eq $pass2) { | |
$htpass->htDelete($user); | |
$htpass->htpasswd($user, $pass1); | |
print "Adding password for user ${user}\n"; | |
} | |
else { | |
print "htpasswd: password verification error\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment