2021-08-02 01:31:06 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
##
|
|
|
|
## Author......: See docs/credits.txt
|
|
|
|
## License.....: MIT
|
|
|
|
##
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Digest::SHA qw (sha1_hex);
|
|
|
|
|
2021-08-06 13:58:19 +00:00
|
|
|
sub module_constraints { [[0, 256], [40, 40], [0, 9], [40, 40], [-1, -1]] }
|
2021-08-02 01:31:06 +00:00
|
|
|
|
|
|
|
sub module_generate_hash
|
|
|
|
{
|
|
|
|
my $word = shift;
|
2021-08-03 21:52:45 +00:00
|
|
|
my $salt = shift || random_hex_string (40);
|
2021-08-02 01:31:06 +00:00
|
|
|
|
|
|
|
my $digest = sha1_hex ('--' . $salt . '--' . $word . '--');
|
|
|
|
|
|
|
|
my $hash = sprintf ("%s:%s", $digest, $salt);
|
|
|
|
|
|
|
|
return $hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub module_verify_hash
|
|
|
|
{
|
|
|
|
my $line = shift;
|
|
|
|
|
|
|
|
my ($hash, $salt, $word) = split (':', $line);
|
|
|
|
|
|
|
|
return unless defined $hash;
|
|
|
|
return unless defined $salt;
|
|
|
|
return unless defined $word;
|
|
|
|
|
|
|
|
my $word_packed = pack_if_HEX_notation ($word);
|
|
|
|
|
|
|
|
my $new_hash = module_generate_hash ($word_packed, $salt);
|
|
|
|
|
|
|
|
return ($new_hash, $word);
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|