Skip to content

Instantly share code, notes, and snippets.

@rc4
Last active June 1, 2022 22:36
Show Gist options
  • Save rc4/305a7f9cf945127fd045546cad4b13e5 to your computer and use it in GitHub Desktop.
Save rc4/305a7f9cf945127fd045546cad4b13e5 to your computer and use it in GitHub Desktop.
Simple Perl script to generate salted SHA-256 password for FreeRADIUS PAP authentication (see https://networkradius.com/doc/current/raddb/mods-available/pap.html). No external dependencies; only uses core modules (so it should work out-of-the-box on any system).
#!/usr/bin/perl
use Digest::SHA;
use MIME::Base64;
print "Enter password: ";
system( 'stty -echo' );
chomp( $password = <STDIN> );
system( 'stty echo' );
print "\n";
$sha = Digest::SHA->new( 'sha256' );
$sha->add( $password );
$sha->add( $^T . $$ ); # Use Unix epoch at start of execution & current PID for the salt
$enc = encode_base64( $sha->digest . $^T . $$, '' );
print "All set! Add this line to your config:\n";
print "(username) Password-With-Header := \"{ssha256}$enc\"\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment