SQLite User Forum

User authentication via PRAGMA?
Login

User authentication via PRAGMA?

(1) By anonymous on 2023-08-30 13:01:50 [link] [source]

Hi, I would like to integrate SQLite with authentication into the NodeJS project. I am looking to know if it is possible to setup authentication parameters and to perform authentication via, for example, the PRAGMA statement? I am looking into NOT using C-level API that is offered by SQLite user authentication module, or wrapping the API into the Javascript. Thanks!

(2) By jose isaias cabrera (jicman) on 2023-08-30 13:53:05 in reply to 1 [link] [source]

Are you talking about something like:

PRAGMA user_login = 'jose'
PRAGRA user_pword = 'myPassW0rd'

Is it something like that?

(3) By anonymous on 2023-08-30 14:10:17 in reply to 2 [link] [source]

Yes, I am thinking something like that. I have been looking into the page which lists the supported PRAGMA statements, however, I haven't found anything that would perform authentication.

(4) By Donal Fellows (dkfellows) on 2023-08-30 15:46:06 in reply to 3 [link] [source]

But SQLite isn't designed to be a database server accessed by multiple different users at once. That has many impacts, one of which is that auth basically just comes down to "can you read and write the relevant file(s)". What is the scenario you are thinking of where someone can read and write to the DB file but still needs to authenticate to the DB?

(5) By anonymous on 2023-08-30 16:18:10 in reply to 4 [link] [source]

Thanks for your reply.

I would like to protect SQLite database file from malicious users with a password. The SQLite database would be used by only one user and that "user" would be application. So it would come down to "application is the only user to read and write the storage file".

I am basically looking into authenticating from the Javascript code and checking if SQLite provides a way to authenticate via PRAGMA. Otherwise, I would need to expose C-level API for authentication to Javascript.

I am only looking into what is supported so far, so I know my next steps.

(6) By Simon Slavin (slavin) on 2023-08-31 14:03:44 in reply to 5 [link] [source]

You might be talking about permission or encryption.

You don't need PRAGMAs. Just put some code in your program to read account & password from a table called Users and check them. It will make the program look like it has some security.

The problem with storing the password in the database is that SQLite isn't a client/server system. To have permission to open a SQLite database, a user or program needs permission to read the file from disk. And if they or your program have that, a hacker can make a copy of your file and inspect it at their leisure, taking as much time as they like to crack any passwords.

To make that harder you need encryption, and encryption is a paid extention to SQLite. See here for details.

https://sqlite.org/com/see.html

(7) By anonymous on 2023-09-01 09:08:18 in reply to 6 [link] [source]

Hi, thanks for the reply.

You made a good point to rule out username/password solution.

I haven't studied a solution that would use permissions yet.

SEE sounds as a good and affordable solution. However, due to very intensive operations on the SQLite database (e.g. write/read every second, or even less than a second), could tell more how SEE impacts overall performance of the application?

(8) By Simon Slavin (slavin) on 2023-09-01 21:10:09 in reply to 7 [source]

If I recall correctly, the last time the speed penalty of SEE was mentioned, time trials put it to somewhere between nothing and 3%. Perhaps someone has posted more up-to-date figures I don't know.

Most of the time taken by everything SQLite does is waiting for data to be fetched from storage or written to storage. The amount of time taken by processing (figuring out what your SQL statement means, decrypting an encrypted database page) is small in comparison. This is one reason why SQLite speeds up so much when you switch from Hard Disk to SSD.

Because of this, the speed penalty will depend closely on the read/write pattern and timing of your program, and on your hardware setup: bus speed, storage subsystem, storage driver, ACID-type settings. We can't give you figures for your setup. Sorry.

(9) By anonymous on 2023-09-02 08:11:16 in reply to 8 [link] [source]

Thanks for the information.