Skip to content

Instantly share code, notes, and snippets.

@mschmitt
Last active October 16, 2017 08:46
Show Gist options
  • Save mschmitt/5729532 to your computer and use it in GitHub Desktop.
Save mschmitt/5729532 to your computer and use it in GitHub Desktop.
Check whether a given password matches a given salted hash from /etc/shadow.
#!/usr/bin/perl -w
use strict;
use diagnostics;
use Crypt::Passwd::XS;
print "Paste hash here: ";
my $hash = <>;
print "Enter password (will not echo): ";
system('stty', '-echo');
my $pass = <>;
system('stty', 'echo');
print "\n";
chomp $hash;
chomp $pass;
if (Crypt::Passwd::XS::crypt($pass, $hash) eq $hash){
print "OK: Password and hash match.\n";
}else{
print "SORRY: Password and hash DO NOT match.\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment