Created
January 15, 2017 23:18
-
-
Save bk2204/db56cfbe4c7be31fa8a4b96ed1fc6687 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/perl | |
use strict; | |
use warnings; | |
use Crypt::Passwd::XS; | |
use MIME::Base64; | |
my $password = <STDIN>; | |
chomp $password; | |
open(my $fh, '<', '/dev/urandom'); | |
read($fh, my $buf, 12); | |
close($fh); | |
my $salt = '$6$' . MIME::Base64::encode_base64url($buf); | |
my $encoded = Crypt::Passwd::XS::crypt($password, $salt); | |
# Compare password for validation. | |
if ($encoded eq Crypt::Passwd::XS::crypt($password, $encoded)) { | |
print "Password matches!\n"; | |
} | |
else { | |
print "Password does not match.\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment