Recent

Author Topic: How can I capture the USER_NAME and PASSWORD from TIBDatabase Login?  (Read 2491 times)

RedOctober

  • Sr. Member
  • ****
  • Posts: 452
Platform:  Laz 1.8.1  Fpc 3.0.5, IBX 2.1.0  on Windows Server Essentials 2016

I am using the TIBDatabase component to connect to a database.
I would like my users to use the built-in login prompt in the TIBDatabase component, but I need to capture the username and password that the user just typed in to connect, so that I can store it in a TBufDataset for use all during the session.  When the session is closed, the TBufDataset is discarded so the passwords will not be stored.  I'm wondering how I can capture what the user just entered.  Here is some code I'm trying.  Interestingly, the built-in Login prompt does create a USERNAME parameter, however it doesn't create a PASSWORD parameter.  I need to capture both.

Code: Pascal  [Select][+][-]
  1. ...
  2.     repeat
  3.       try
  4.         fb_db.Connected := True;
  5.  
  6.         if fb_db.Connected then
  7.           begin
  8.             if SameText(ths_usr, 'ASKME') and SameText(ths_pwd, 'ASKME') then
  9.               begin
  10.                 ths_usr := fb_db.Params.Values['USER_NAME'];  //<--- Works!
  11.                 ths_pwd := fb_db.Params.Values['PASSWORD'];  // <-- empty.
  12.               end;
  13. ...
  14.  



dsiders

  • Hero Member
  • *****
  • Posts: 1080
Re: How can I capture the USER_NAME and PASSWORD from TIBDatabase Login?
« Reply #1 on: February 09, 2018, 09:36:19 am »
Platform:  Laz 1.8.1  Fpc 3.0.5, IBX 2.1.0  on Windows Server Essentials 2016

I am using the TIBDatabase component to connect to a database.
I would like my users to use the built-in login prompt in the TIBDatabase component, but I need to capture the username and password that the user just typed in to connect, so that I can store it in a TBufDataset for use all during the session.  When the session is closed, the TBufDataset is discarded so the passwords will not be stored.  I'm wondering how I can capture what the user just entered.  Here is some code I'm trying.  Interestingly, the built-in Login prompt does create a USERNAME parameter, however it doesn't create a PASSWORD parameter.  I need to capture both.

Code: Pascal  [Select][+][-]
  1. ...
  2.     repeat
  3.       try
  4.         fb_db.Connected := True;
  5.  
  6.         if fb_db.Connected then
  7.           begin
  8.             if SameText(ths_usr, 'ASKME') and SameText(ths_pwd, 'ASKME') then
  9.               begin
  10.                 ths_usr := fb_db.Params.Values['USER_NAME'];  //<--- Works!
  11.                 ths_pwd := fb_db.Params.Values['PASSWORD'];  // <-- empty.
  12.               end;
  13. ...
  14.  

TIBDatabase does not expose the user name or password used for the internal Login dialog. In fact, it removes the password from the Params property (if present) when the Login method is completed. So it's obviously by design.

TIBDatabase does however have an OnLogin event handler. It assumes you're implementing your own login dialog (where you could capture and store the credentials) and using the event handler to pass the user name and password to the Login method in its LoginParams argument. The LoginPrompt property could be set to False at that point (since you'd be handling it elsewhere).

Probably not the answer you're hoping for, but I hope that helps.
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

RedOctober

  • Sr. Member
  • ****
  • Posts: 452
Re: How can I capture the USER_NAME and PASSWORD from TIBDatabase Login?
« Reply #2 on: February 09, 2018, 03:41:57 pm »
This will work for me dsiders.  Thanks.

 

TinyPortal © 2005-2018