You are great! PasswordBox works.
I just found a problem though! It gives problem with 'if'.
Look:
procedure TForm1.btnConnClick(Sender: TObject);
begin
Target:='DB1 Connection';
if CredReadGenericCredentials(Target, Username, Password) then
begin
ZConnection1.Database:='localhost';
ZConnection1.Hostname:='xe';
ZConnection1.User:=Username;
ZConnection1.Password:=Password;
zquery1.sql.text:='select * from test';
zquery1.open;
end else
Username:=InputBox('Title','Prompt', Username);
Password:=PasswordBox('Title','Prompt');
if CredWriteGenericCredentials(Target, Username, Password) then
ZConnection1.Database:='localhost';
ZConnection1.Hostname:='xe';
ZConnection1.User:=Username;
ZConnection1.Password:=Password;
Username:='';
Password:='';
zquery1.sql.text:='select * from test';
zquery1.open;
end;
It should work so: if credentials are already stored with that target name you login, instead you are asked username and password.
Problem is that when I store username and password first time it works. If I close and open the application again and I click that button, I'm asked again for the password (not username though).
Is this a bug or my faily if statement?
Edit: yes it was my 'faily if'. Just corrected adding begin and end; after the else. -.-'
Anyway I leave the code if you want to make more corrections. Always apreciated.