Recent

Author Topic: TSQLite3Connection, Password field  (Read 2216 times)

LemonParty

  • Sr. Member
  • ****
  • Posts: 438
TSQLite3Connection, Password field
« on: August 01, 2025, 08:21:18 pm »
Hello.
If I previously set up some password, how can I change it later?
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

Thaddy

  • Hero Member
  • *****
  • Posts: 18944
  • Glad to be alive.
Re: TSQLite3Connection, Password field
« Reply #1 on: August 02, 2025, 05:44:27 am »
You don't store the password, but you store its hash...Everybody knows that.
You  should offer a recovery interface and delete the old hash and create a new one from the new password..
That is because you can't get the password back from the hash. You can not decrypt a hash.
Verification is by comparing hashes not passwords.

If there is an information leak, you don't leak passwords but pretty meaningless hashes.
In principle this has nothing to do with the database, but with the userinterface.
This is not SQLite3 specific.
In SQLite3 you can you a user defined function to hash the password and compare the hashes.
In other databases one usually writes a stored procedure for that.

I have a unit for Windows and Linux for that. Must update it a bit for BCrypt and newer OpenSSL.
Interface is simple:
Code: Pascal  [Select][+][-]
  1. function HashPassword(const password: string): string;cdecl;
  2. function CheckPassword(const entered_password: string; const stored_hash: string): Boolean;cdecl;
Both can be massaged into a UDF.

I will attach it when I have updated it.
« Last Edit: August 02, 2025, 10:47:18 am by Thaddy »
Recovered from removal of tumor in tongue following tongue reconstruction with a part from my leg.

LemonParty

  • Sr. Member
  • ****
  • Posts: 438
Re: TSQLite3Connection, Password field
« Reply #2 on: August 02, 2025, 03:09:21 pm »
My question is about a bit different situation. What if I created a database with one password and then I want encrypt database with different password? Should I create a new database in this case (and do a copy by myself)?
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

jcmontherock

  • Sr. Member
  • ****
  • Posts: 347
Re: TSQLite3Connection, Password field
« Reply #3 on: August 02, 2025, 05:45:37 pm »
« Last Edit: August 02, 2025, 11:49:00 pm by jcmontherock »
Windows 11 UTF8-64 - Lazarus 4.6-64 - FPC 3.2.2

LemonParty

  • Sr. Member
  • ****
  • Posts: 438
Re: TSQLite3Connection, Password field
« Reply #4 on: August 03, 2025, 03:45:01 pm »
Thank you for help.
This command do the thing:
Code: Pascal  [Select][+][-]
  1. SQLite3Connection1.ExecuteDirect('PRAGMA rekey = "' + txtNew.Text + '";');
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

 

TinyPortal © 2005-2018