Recent

Author Topic: InputBox with masked or white color text  (Read 1613 times)

Conte

  • New Member
  • *
  • Posts: 27
InputBox with masked or white color text
« on: October 04, 2021, 09:39:37 pm »
I need an InputBox to enter a password. I'd like that the text is masked or in white color to not be seen.
Is there a way to do that?

PS: I can't use InputQuery cause the variable is a WideString and it gives me error. If you know a way to use a WideString in InputQuery the problem is solved cause I make TRUE the masked option.

balazsszekely

  • Guest
Re: InputBox with masked or white color text
« Reply #1 on: October 04, 2021, 09:51:07 pm »
I need an InputBox to enter a password. I'd like that the text is masked or in white color to not be seen.
Is there a way to do that?

PS: I can't use InputQuery cause the variable is a WideString and it gives me error. If you know a way to use a WideString in InputQuery the problem is solved cause I make TRUE the masked option.
PasswordBox perhaps?

Conte

  • New Member
  • *
  • Posts: 27
Re: InputBox with masked or white color text
« Reply #2 on: October 04, 2021, 10:36:54 pm »
You are great! PasswordBox works.
I just found a problem though! It gives problem with 'if'.

Look:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.btnConnClick(Sender: TObject);
  2. begin
  3.   Target:='DB1 Connection';
  4.   if CredReadGenericCredentials(Target, Username, Password) then
  5.     begin
  6.     ZConnection1.Database:='localhost';
  7.     ZConnection1.Hostname:='xe';
  8.     ZConnection1.User:=Username;
  9.     ZConnection1.Password:=Password;
  10.     zquery1.sql.text:='select * from test';
  11.     zquery1.open;
  12.     end else
  13.       Username:=InputBox('Title','Prompt', Username);
  14.       Password:=PasswordBox('Title','Prompt');
  15.       if CredWriteGenericCredentials(Target, Username, Password) then
  16.       ZConnection1.Database:='localhost';
  17.     ZConnection1.Hostname:='xe';
  18.     ZConnection1.User:=Username;
  19.     ZConnection1.Password:=Password;
  20.     Username:='';
  21.     Password:='';
  22.     zquery1.sql.text:='select * from test';
  23.     zquery1.open;
  24.     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. :)
« Last Edit: October 04, 2021, 10:51:39 pm by Conte »

Conte

  • New Member
  • *
  • Posts: 27
Re: InputBox with masked or white color text
« Reply #3 on: October 04, 2021, 11:53:18 pm »
I'd add another question about the InputBox that has a strange functioning.
If I press 'Cancel' it enter a blank value instead of nothing (exiting). Is there a way to avoid that?

balazsszekely

  • Guest
Re: InputBox with masked or white color text
« Reply #4 on: October 05, 2021, 09:06:36 am »
@conte

Try attached project, but don't forget to change the values inside mainform's button1click.

Tested with: Lazarus Trunk/FPC 3.2.2(32 bit), Windows 10(64 bit)

 

TinyPortal © 2005-2018