56 lines
1.8 KiB
Text
56 lines
1.8 KiB
Text
$ include "seed7_05.s7i";
|
|
|
|
const func string: generate (in integer: length) is func
|
|
result
|
|
var string: password is "";
|
|
local
|
|
const set of char: allowed is {'!' .. '~'} - {'\\', '`'};
|
|
const set of char: special is allowed - {'A' .. 'Z'} | {'a' .. 'z'} | {'0' .. '9'};
|
|
var integer: index is 0;
|
|
var char: ch is ' ';
|
|
var boolean: ucPresent is FALSE;
|
|
var boolean: lcPresent is FALSE;
|
|
var boolean: digitPresent is FALSE;
|
|
var boolean: specialPresent is FALSE;
|
|
begin
|
|
repeat
|
|
password := "";
|
|
ucPresent := FALSE;
|
|
lcPresent := FALSE;
|
|
digitPresent := FALSE;
|
|
specialPresent := FALSE;
|
|
for index range 1 to length do
|
|
ch := rand(allowed);
|
|
ucPresent := ucPresent or ch in {'A' .. 'Z'};
|
|
lcPresent := lcPresent or ch in {'a' .. 'z'};
|
|
digitPresent := digitPresent or ch in {'0' .. '9'};
|
|
specialPresent := specialPresent or ch in special;
|
|
password &:= ch;
|
|
end for;
|
|
until ucPresent and lcPresent and digitPresent and specialPresent;
|
|
end func;
|
|
|
|
const proc: main is func
|
|
local
|
|
var integer: length is 0;
|
|
var integer: count is 0;
|
|
begin
|
|
if length(argv(PROGRAM)) <> 2 or not isDigitString(argv(PROGRAM)[1]) or
|
|
not isDigitString(argv(PROGRAM)[2]) then
|
|
writeln("Usage: pwgen length count");
|
|
writeln(" pwgen -?");
|
|
writeln("length: The length of the password (min 4)");
|
|
writeln("count: How many passwords should be generated");
|
|
writeln("-? Write this text");
|
|
else
|
|
length := integer(argv(PROGRAM)[1]);
|
|
count := integer(argv(PROGRAM)[2]);
|
|
if length < 4 then
|
|
writeln("Passwords must be at least 4 characters long.");
|
|
else
|
|
for count do
|
|
writeln(generate(length));
|
|
end for;
|
|
end if;
|
|
end if;
|
|
end func;
|