Hmm, I am not a security expert. Don't blame me if I'm giving you bad advice now...
First of all, do you really need a password? Don't you trust your collegues? Having to enter a password for no good reason is annoying. And if you have curious collegues just the presence of a password may trigger them to find a way how to by-pass it...
Anyway, let's assume: you need a password.
The ini file is stored in the directory returned by GetAppConfigFile. In a "normal PC", this directory is in your home directory, and another user does not have access to this directory - this is rather safe.
But: probably the PC running this pump system is accessible to all employees/students/etc working in that laboratory, and there is a "general" account, nobody logs in under his own ID. So - this argument is not very strong...
You could store a hash of the password, rather than the password itself. When the user enters the password, the hash is calculated and compared with the stored hash (rather than comparing the passwords directly). Example:
uses
md5;
function CalcPasswordHash(APassword: String): String;
var
md5Digest: TMDDigest;
begin
md5Digest := MD5String(APassword);
Result := md5Print(md5Digest);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
pwd: String;
begin
// Application called for the first time --> define the password
if not FileExists(CalcIniFileName) then
begin
pwd := PasswordBox('Define password', 'Define the password that a user will need to run this application');
FPassword := CalcPasswordHash(pwd);
WriteToIni(true);
FPassword := '';
end;
ReadFromIni;
pwd := PasswordBox('Enter password', 'Password to run this application');
if FPassword <> CalcPasswordHash(pwd) then
begin
MessageDlg('Incorrect password. Terminating...', mtError, [mbOK], 0);
Application.Terminate;
end;
...
About the risk of deleting the ini file: Rewrite my code above such that the application does not start when
/1/ the entered password is not correct (like before), or
/2/ the ini file is not found.
For this to work, you must have a second program which only has the purpose to create an ini file before the first start of the application, and, of course, it must define the password and write its hash to the ini file. This tool should only be accessible to you (and trusted collegues), do not store it on the same machine on which the pumpdown program runs.
OK... Still, a clever collegue may notice that the ini file contains an md5 hash of the password (from its length). He could write a tool like yours and create an md5 hash for a new password, copy it into the ini file and now could run the pump although he is not allowed to... To make this hack more difficult, you could split the ini file in two parts: one with the general settings (window sizes, positions, etc), stored at the current place, and one with the password hash only stored at a different place: ideally on a server so that only you have write access, or in the Windows registry key HK_LocalMachine to which only admins have write access (*), or (well... "security by obscurity"...) in some other directory and renamed so that it is not obvious that it belongs to the pumpdown program.
(*) Hopefully, the lab PC running the pump is not configured to provide admin rights to all users...