More entropy
This commit is contained in:
parent
b9a9ecf3ef
commit
d3e5db8305
40
Password.pm
40
Password.pm
@ -7,6 +7,9 @@ use utf8;
|
|||||||
use Database;
|
use Database;
|
||||||
use GPG;
|
use GPG;
|
||||||
|
|
||||||
|
use Digest::MD5;
|
||||||
|
use MIME::Base64;
|
||||||
|
|
||||||
# Debug
|
# Debug
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
|
||||||
@ -151,17 +154,40 @@ sub save {
|
|||||||
# Generate password
|
# Generate password
|
||||||
sub generate {
|
sub generate {
|
||||||
my $value;
|
my $value;
|
||||||
|
|
||||||
|
# Defaults
|
||||||
|
my $length = 16;
|
||||||
|
|
||||||
open my $rnd, "<", "/dev/random";
|
my $digest;
|
||||||
read $rnd, $value, 32;
|
for (1..32) {
|
||||||
my $c = unpack( "H*", $value );
|
open my $rnd, "<", "/dev/urandom";
|
||||||
close $rnd;
|
read $rnd, $value, 1000;
|
||||||
|
my $c = unpack( "H*", $value );
|
||||||
|
close $rnd;
|
||||||
|
|
||||||
my @chars = split( //, $c );
|
# MORE ENTROPY
|
||||||
push @chars, $_ for ( '!', '@', '(', ')', 'A' .. 'Z' );
|
my $ctx = Digest::MD5->new();
|
||||||
|
$ctx->add($c);
|
||||||
|
|
||||||
|
# MORE
|
||||||
|
my $encoded = encode_base64( $ctx->hexdigest() );
|
||||||
|
$encoded =~ s/=//g;
|
||||||
|
$encoded =~ s/\n//g;
|
||||||
|
|
||||||
|
$digest .= $encoded;
|
||||||
|
}
|
||||||
|
|
||||||
|
my @chars = split( //, $digest );
|
||||||
|
|
||||||
|
my @r_special = ( '!', '@', '(', ')', '#', '$', '%', '^', '&' );
|
||||||
|
for (1..10) {
|
||||||
|
foreach my $special (@r_special) {
|
||||||
|
$chars[ rand(@chars) ] = $special ];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
my $string;
|
my $string;
|
||||||
$string .= $chars[ rand @chars ] for 1 .. 16;
|
$string .= $chars[ rand @chars ] for 1 .. $length;
|
||||||
|
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user