Skip to content

Instantly share code, notes, and snippets.

@maspalio
Created January 5, 2016 12:24
Show Gist options
  • Save maspalio/1396412fcfc0d9e2f6b0 to your computer and use it in GitHub Desktop.
Save maspalio/1396412fcfc0d9e2f6b0 to your computer and use it in GitHub Desktop.
mkpasswd -m sha-512 $pass $( openssl rand -base64 16 | tr -d '+=' | head -c 16 )
sub hashed_password {
my ( $pass ) = @_;
# mkpasswd -m sha-512 $pass $( openssl rand -base64 16 | tr -d '+=' | head -c 16 )
my $get_salt = sub {
my ( $out, $err );
my @command = split ' ', 'openssl rand -base64 16';
run3 \@command, undef, \$out, \$err;
chomp $out;
$out =~ s/[+=]//g;
return substr $out, 0, 16;
};
my ( $out, $err );
my @command = split ' ', "mkpasswd -m sha-512 $pass " . $get_salt->();
run3 \@command, undef, \$out, \$err;
chomp $out;
return $out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment