Password generator: Difference between revisions

Content added Content deleted
Line 3,076: Line 3,076:
subset PositiveInt of Int where * > 0;
subset PositiveInt of Int where * > 0;


sub MAIN( PositiveInt :$c = 0, MinumumPasswordLength :$l = 8, Str :$x = '' )
sub MAIN( PositiveInt :c(:$count) = 0, MinumumPasswordLength :l(:$length) = 8, Str :x(:$exclude) = '' )
{
{
.say for generate-passwords( $c, $l, char-groups( $x.comb ) );
.say for password-characters( char-groups( $exclude.comb ) )
.batch( $length )
.map( *.pick: Inf ) # shuffle, so we don't get a predictable pattern
.map( *.join )
.head( $count );
}
}


Line 3,092: Line 3,096:
.map( * (-) @exclude )
.map( * (-) @exclude )
.grep( *.so );
.grep( *.so );
}

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


Line 3,106: Line 3,101:
{
{
( |@char-groups xx Inf ).map( *.pick );
( |@char-groups xx Inf ).map( *.pick );
}

sub USAGE()
{
say qq:to/END/;
Specify a count: --c=1 (mandatory, at least 1),
Specify a length: --l=8 (default 8),
Specify characters to exclude: --x=... (must escape characters significant to the shell)
END
}
}
</lang>
</lang>