Skip to content

Instantly share code, notes, and snippets.

@bk2204
Created January 15, 2017 23:18
Show Gist options
  • Save bk2204/db56cfbe4c7be31fa8a4b96ed1fc6687 to your computer and use it in GitHub Desktop.
Save bk2204/db56cfbe4c7be31fa8a4b96ed1fc6687 to your computer and use it in GitHub Desktop.
#!/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