Password generator: Difference between revisions

Added XPL0 example.
(Added XPL0 example.)
Line 5,767:
 
The generated passwords have been written to the file pwds.txt
</pre>
 
=={{header|XPL0}}==
{{trans|Python}}
<syntaxhighlight lang "XPL0">string 0;
 
func In(C, Str);
char C, Str;
[while Str(0) do
if C = Str(0) then return true else Str:= Str+1;
return false;
];
 
func New_password(Length, Readable);
int Length, Readable, I, C;
char Password_chars(100), Punctuation, Visually_similar;
[if Length < 4 then
[Text(0, "Password length = "); IntOut(0, Length);
Text(0, " is too short, minimum length = 4.");
return "";
];
Punctuation:= "!^"#$%&\'()*+,-./:;<=>?@[]^^_{|}~";
Visually_similar:= "Il1O05S2Z";
for I:= 0 to Length-1 do
[case Ran(4) of
0: C:= Ran(26) + ^a;
1: C:= Ran(26) + ^A;
2: C:= Ran(10) + ^0;
3: C:= Punctuation(Ran(31))
other [];
Password_chars(I):= C;
if Readable and In(C, Visually_similar) then I:= I-1;
];
Password_chars(I):= 0;
return Password_chars;
];
 
proc Password_generator(Length, Qty, Readable);
int Length, Qty, Readable, I;
for I:= 0 to Qty-1 do
[Text(0, New_password(Length, Readable)); CrLf(0)];
 
[Password_generator(14, 4, true);
Password_generator( 8, 4, false);
]</syntaxhighlight>
{{out}}
<pre>
GojA9ep6=3|U,\
U9@p|f'WH7+&TM
8=E7xvm6J9Y([q
zrknig;8Pv+(Va
37s11T68
Ir)wY0P<
54d3o]Ga
95??s]"O
</pre>
 
297

edits