Hay everyone. Im busy creating a program, but first you have to log in with a little form I made. I thought about using a registry entry, but I dont know how to use Tregistry. It should also be possible to use on a network pc with only client level access.

What would the code be for when you run the program? It should put the password and username into the registry if they dont exist already, and if they exist they should be read into constants 'Password' and 'Username'.

I made now a simple function explaining everything.

function Authentificate(user : string;password : string) : boolean;
var
//Add in uses Registry
//if the authentification be success he will return true, else he will return false.
reg : TRegistry;

begin
try
Reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE; //put the RootKey, you can see them in the RegEdit
try begin
Reg.OpenKey('Software/MyAuth', true)
//Open the Key MyAuth located in software and gives the access to the program create //the key if it dont exists
if (User = Reg.ReadString('Username')) and (Password = Reg.ReadString('Password')) then //check if the user and password are equal with the strings in //Software/MyAuth/Username and Password
Result := true else Result := false;
end;
except
Result := false;
end;
Finally
Reg.Free
end;
end;

Thanks man, really appreciated. Would this work on any PC or must it have admin access?

The following is my current code for the login system where it gets the password etc. from the registry or prompts the user to create them if they dont exist. At the point where the program has to add the data to the registry it gives me an exception. I know the code is probably horrible, but please fix it. Don't change it too much, just please make it work.

procedure TFormSplash.bmbLoginClick(Sender: TObject);
var
sInvoerPass, sInvoerUser, sUsername, sPassword : string;
reg : TRegistry;
begin

  //INVOER
  sInvoerPass := ledPassword.Text;
  sInvoerUser := ledLogin.Text;

  reg := TRegistry.Create;
  reg.RootKey := HKEY_LOCAL_MACHINE;
  reg.OpenKey('Software/ProgAuthM', False);

  if reg.KeyExists('Software/ProgAuthM') = True
  then begin
    sUsername := reg.ReadString('Username');
    sPassword := reg.ReadString('Password');
  end
  else begin
    reg.OpenKey('Software/ProgAuthM', True);
    reg.WriteString('Username', InputBox('Gebruikersnaam', 'Voer gewensde gebruikersnaam in:',''));
    reg.WriteString('Password',InputBox('Password','Voer gewensde kodewoord in:',''));
  end;
This article has been dead for over six months. Start a new discussion instead.