More computing stuff
May. 27th, 2018 02:20 pm This is a simple Pascal program that should generate secure or simple passwords for a variety of sites. At the moment, it just generates the passwords. It does not save them anywhere. I need to figure out how to save the file with something other than a clear text file. That's going to be a bit difficult as I don't know how to write these algorithms. It might be an interesting thing to try though.
In any case, here's the code.
In any case, here's the code.
program password_generator;
uses crt;
var
numchars: integer;
password: string[25];
z: integer;
{-----------------------------------------------------------------------------}
{ The least officient way to assign a random value to a variable ever. }
{-----------------------------------------------------------------------------}
function determine_Upper (var Upcasechar: integer): char;
begin
case UpcaseChar of
0: determine_Upper:= 'A';
1: determine_Upper:= 'B';
2: determine_Upper:= 'C';
3: determine_Upper:= 'D';
4: determine_Upper:= 'E';
5: determine_Upper:= 'F';
6: determine_Upper:= 'G';
7: determine_Upper:= 'H';
8: determine_Upper:= 'I';
9: determine_Upper:= 'J';
10: determine_Upper:= 'K';
11: determine_Upper:= 'L';
12: determine_Upper:= 'M';
13: determine_Upper:= 'N';
14: determine_Upper:= 'O';
15: determine_Upper:= 'P';
16: determine_Upper:= 'Q';
17: determine_Upper:= 'R';
18: determine_Upper:= 'S';
19: determine_Upper:= 'T';
20: determine_Upper:= 'U';
21: determine_Upper:= 'V';
22: determine_Upper:= 'W';
23: determine_Upper:= 'X';
24: determine_Upper:= 'Y';
25: determine_Upper:= 'Z';
end;
end;
{-----------------------------------------------------------------------------}
{ See the previous function's comment section. }
{-----------------------------------------------------------------------------}
function determine_Lower (var Lowcasechar: integer): char;
begin
case Lowcasechar of
0: determine_Lower:= 'a';
1: determine_Lower:= 'b';
2: determine_Lower:= 'c';
3: determine_Lower:= 'd';
4: determine_Lower:= 'e';
5: determine_Lower:= 'f';
6: determine_Lower:= 'g';
7: determine_Lower:= 'h';
8: determine_Lower:= 'i';
9: determine_Lower:= 'j';
10: determine_Lower:= 'k';
11: determine_Lower:= 'l';
12: determine_Lower:= 'm';
13: determine_Lower:= 'n';
14: determine_Lower:= 'o';
15: determine_Lower:= 'p';
16: determine_Lower:= 'q';
17: determine_Lower:= 'r';
18: determine_Lower:= 's';
19: determine_Lower:= 't';
20: determine_Lower:= 'u';
21: determine_Lower:= 'v';
22: determine_Lower:= 'w';
23: determine_Lower:= 'x';
24: determine_Lower:= 'y';
25: determine_Lower:= 'z';
end;
end;
{-----------------------------------------------------------------------------}
{ This adds the special character into the password for more secure passwords.}
{-----------------------------------------------------------------------------}
function generate_special: char;
var
assignchar: integer;
begin
assignchar:= random(4)+1;
case assignchar of
1: generate_special:= '!';
2: generate_special:= '#';
3: generate_special:= '&';
4: generate_special:= '%';
end;
end;
{-----------------------------------------------------------------------------}
{ This will generate a complex password for the user. It will do this using }
{ random character generation. It will use a combination of uppercase and }
{ lower case letters. The program will then copy the characters into a string }
{ The position of the special character is generated randomly as well. }
{-----------------------------------------------------------------------------}
procedure generate_complex;
var
specialcharnum: integer;
isupcase: integer;
loopcounter: integer;
gcconvertchar: char;
gc_simple_rand_char: integer;
begin
specialcharnum:= 0;
isupcase:= 0;
clrscr;
gotoxy(1,1);
writeln('Generating complex password now.');
specialcharnum:= random(numchars)+1;
for loopcounter:= 1 to numchars do
begin
gc_simple_rand_char:= random(26);
if (loopcounter <> specialcharnum) then
begin
isupcase:= random(2);
case isupcase of
0: gcconvertchar:= determine_Upper(gc_simple_rand_char);
1: gcconvertchar:= determine_Lower(gc_simple_rand_char);
end;
end
else
begin
gcconvertchar:= generate_special;
password[loopcounter]:= gcconvertchar;
end;
password[loopcounter]:= gcconvertchar;
end;
for loopcounter:= 0 to numchars do
begin
write (password[loopcounter]);
end;
writeln ('');
write ('Press enter to continue.');
readln;
end;
{-----------------------------------------------------------------------------}
{ This is a scaled-down version of the generate complex procedure. It only }
{ needs to generate valid Ascii characters. }
{-----------------------------------------------------------------------------}
procedure generate_simple;
var
simple_Rand_char: integer;
convertchar: char;
determineCase: integer;
loopcounter: integer;
begin
clrscr;
writeln ('Generating Password now.');
determineCase:= 0;
convertchar:= ' ';
for loopcounter:= 0 to numchars do
begin
determineCase:= random(2);
simple_Rand_Char:= random (26);
case determineCase of
0: convertchar:= determine_Upper(simple_Rand_char);
1: convertchar:= determine_Lower(simple_Rand_Char);
end;
password[loopcounter]:= convertchar;
end;
write ('Your password is: ');
for loopcounter:= 0 to numchars do
begin
write (password[loopcounter]);
end;
writeln ('');
readln;
end;
{------------------------------------------------------------------------------}
{ Ask the user how long they want their newly generated password to be. }
{------------------------------------------------------------------------------}
procedure get_password_length;
var
lengthset: boolean;
label tryagain;
begin
tryagain:
clrscr;
lengthset:= false;
writeln ('How long would you like your password to be?');
try
readln (numchars);
finally
writeln ('You''re going to have to try again.');
end;
if (numchars < 8) or (numchars > 25) then
begin
writeln ('That was not a valid number. Press enter to continue.');
readln;
goto tryagain;
end;
end;
{-----------------------------------------------------------------------------}
{ This program lets the user choose whether they want to generate a simple }
{ password or a complex password. }
{-----------------------------------------------------------------------------}
procedure choose_simple_or_complex;
var
choice: char;
label redo;
begin
choice:= 'x';
redo:
clrscr;
gotoxy (1,1);
write('--------------------------------------------------------------------');
gotoxy (1,2);
write (' Would you like to genarate a (S)imple password or a (C)omplex ');
gotoxy (1,3);
write (' password? ');
gotoxy( 1,4);
write('-------------------------------------------------------------------');
choice:= readkey;
choice:= upcase (choice);
get_password_length;
if (choice = 'S') then
begin
generate_simple;
end
else if (choice = 'C') then
begin
generate_complex;
end
else
begin
gotoxy (1,5);
write ('I did not understand that. Press any key to continue.');
choice:= readkey;
goto redo;
end;
end;
{------------------------------------------------------------------------------}
{ All this does is draw a simple intro screen to tell the user what the program}
{ is for. }
{------------------------------------------------------------------------------}
procedure draw_intro_screen;
var
throwaway: char;
begin;
throwaway:= 'z';
gotoxy (1,1);
writeln ('Sinister Software Solutions');
gotoxy (23,13);
write ('Simple Password Generator');
gotoxy (1,23);
write ('Press any key to continue.');
throwaway:= readkey;
choose_simple_or_complex;
end;
{=============================================================================}
begin
for z:= 0 to 25 do
begin
password[z]:= ' ';
end;
randomize;
clrscr;
draw_intro_screen;
end.
You'll need Lazarus or an older copy of Turbo Pascal to copy and run it. (The Free Pascal IDE also works, since it uses the same compiler Lazarus does.) There will be a newer version that will save the passwords. This is done in part because I think that Google Chrome's new secure password generation is a good thing, but I don't trust cloud computing services to store information. They are more likely to be targets of a hack than my home computer.
You'll need Lazarus or an older copy of Turbo Pascal to copy and run it. (The Free Pascal IDE also works, since it uses the same compiler Lazarus does.) There will be a newer version that will save the passwords. This is done in part because I think that Google Chrome's new secure password generation is a good thing, but I don't trust cloud computing services to store information. They are more likely to be targets of a hack than my home computer.