Password generator: Difference between revisions
→functional: Raku alternate version upgraded to meet task specs
m (Commodore BASIC - Minor clarification.) |
SqrtNegInf (talk | contribs) (→functional: Raku alternate version upgraded to meet task specs) |
||
Line 3,470:
===functional===
subset MinimumPasswordLength of Int where * >= 4;▼
subset NumberOfPasswords of UInt where * != 0;▼
sub MAIN( NumberOfPasswords:
<lang perl6>▼
&USAGE() if 1 == (.comb ∖ $exclude.comb).elems for @char-groups;
▲subset MinimumPasswordLength of Int where * >= 4;
▲subset NumberOfPasswords of UInt where * != 0;
▲sub MAIN( NumberOfPasswords:D :c(:$count), MinimumPasswordLength :l(:$length) = 8, Str :x(:$exclude) = '' )
▲ .say for password-characters( char-groups( $exclude.comb ) )
.map( *.pick: Inf ) # shuffle, so we don't get a predictable pattern
.map( *.join )
Line 3,486 ⟶ 3,488:
}
sub
(( char-groups($exclude, $len) xx Inf ).map: *.pick).batch($len-4) )
▲ ['a' .. 'z'],
▲ ['A' .. 'Z'],
▲ ['0' .. '9'],
▲ < $ % & \ ` ~ ! * + , - . / : ; = ? @ ^ _ ~ [ ] ( ) { | } # ' " \< \> >;
▲ @char-groups
▲ .map( * (-) @exclude )
}
multi char-groups( $exclude ) { | @char-groups.map( * (-) $exclude.comb ) }
multi char-groups( $exclude, $max-weight ) { flat (char-groups($exclude)>>.keys.map: {$_ xx ^$max-weight .roll}) }
▲ ( |@char-groups xx Inf ).map: *.pick;
sub USAGE() {
say qq:to/END/;
Specify a length: -l=10 (minimum 4)
Specify a count: -c=5 (minimum 1)
Specify characters to exclude: -x=xkcd (optional)
Password must have at least one of each: lowercase letter, uppercase letter, digit, punctuation.
END
'''Sample output:'''
Without parameters:
<pre>d[G2r4;i</pre>
With passed parameters: -c=
<pre>
CEpZ>#4'rO7d
pn(5B;wb66DM
KA;3T7=s+I5{
LL<tB~L1~Y*q</pre>
=={{header|REXX}}==
|