Password generator: Difference between revisions

Content added Content deleted
Line 3,083: Line 3,083:
sub char-groups( @exclude )
sub char-groups( @exclude )
{
{
my %char-groups =
state @char-groups =
lc => ['a' .. 'z'],
['a' .. 'z'],
uc => ['A' .. 'Z'],
['A' .. 'Z'],
digit => ['0' .. '9'],
['0' .. '9'],
special => < $ % & \ ` ~ ! * + , - . / : ; = ? @ ^ _ ~ [ ] ( ) { | } # ' " \< \> >;
< $ % & \ ` ~ ! * + , - . / : ; = ? @ ^ _ ~ [ ] ( ) { | } # ' " \< \> >;


for %char-groups.keys
@char-groups
.map( * (-) @exclude )
{
.grep( *.so );
%char-groups{ $_ } = %char-groups{ $_ } (-) @exclude;
%char-groups{ $_ }:delete unless %char-groups{ $_ };
}

%char-groups;
}
}


sub generate-passwords( UInt $count, UInt $length, %char-groups )
sub generate-passwords( UInt $count, UInt $length, @char-groups )
{
{
password-characters( %char-groups )
password-characters( @char-groups )
.batch( $length )
.batch( $length )
.map( *.pick: Inf ) # shuffle, so we don't get a predictable pattern
.map( *.pick: Inf ) # shuffle, so we don't get a predictable pattern
Line 3,107: Line 3,103:
}
}


sub password-characters( %char-groups )
sub password-characters( @char-groups )
{
{
gather loop {
gather loop { take .pick for @char-groups }
take %char-groups{ .key }.pick for %char-groups
};
}
}