Login App – Useing External Database List

Here’s a program I wrote with the help of a friend who’s a little more familiar with Free Pascal than I am. I used Lazarus to program this. If you don’t know what Lazarus is, then you should look it up. It’s amazing.

This program will use an external list of names and passwords to grant access to whatever you want. You’d probably want to implement some sort of encryption/decryption in this system, but the basic framework of a login application is here. I had a basic text file called “doing” functioning as my database file. I also renamed the file extension from “.txt” to “.filter” just for the fun of it. Obviously you can change these to whatever you want as long as you change it in the program and recompile it.

Here’s the code:

Ext_list_Login_app_proj.zip



program Ext_list_Login_app_proj;

{$mode objfpc}{$H+}

uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes
{ you can add units after this };

var
name:string;
real_name:string;
pass:string;
real_pass:string;

{This program is divided up into procedures just to make it a little easier for me.}

procedure login_complete;
begin
writeln();
writeln('Hey you remembered BOTH your username AND password!');
writeln('If you wanted to really do something important with this,');
writeln('than you would probably launch a program or something at this point.');
writeln('But right now, this program does nothing like that.');
writeln();
writeln();

end;

function check_pass(const name:string;const pass:string): boolean;
var
f:textfile;
s:string;
x:integer;

begin
assignfile(f, 'doing.filter');
reset(f);
try
while not eof(f) do
begin
readln(f,s);
x:=pos(':',s);
result:=(copy(s, 1, x-1)=name) and (copy(s, x+1, length(s)-x)=pass);
if result then exit;
end;
finally
closefile(f);
end;
end;

procedure login;
begin
writeln();
writeln('Enter Username:');
readln(name);
writeln();
writeln('Enter Password:');
readln(pass);

{Now that we have user input, the application will now verify that information with the correct answers}

if check_pass(name, pass)then
login_complete;
end
else
begin
writeln();
writeln('Oops. You entered the wrong username and password combination.');
writeln('Try again.');
login;

end;
end;

{"Main" program below}

begin

writeln('Welcome to the Login Application!');
writeln();

login;
writeln('Press <enter> to quit.');
readln();
end.


Rate this Post/Page