2

I m trying to open password protected db using sqlite3 in c++ means programmatically.
sqlite3 *m_sqlite; int ret = sqlite3_open("test.db", &m_sqlite); But its for open a normal db , there is any other function to open password protected db.

1 Answer 1

3

You can use sqlite3_user_authenticate to open db which requires authentication.

The syntax goes as below.

int sqlite3_user_authenticate(
     sqlite3 *db,           /* The database connection */
     const char *zUsername, /* Username */
     const char *aPW,       /* Password or credentials */
     int nPW                /* Number of bytes in aPW[] */
   );

Call sequence goes as below.

int ret = sqlite3_open("test.db", &m_sqlite);
ret = sqlite3_user_authenticate(m_sqlite,"username","password",8);

For more info refer https://www.sqlite.org/src/doc/trunk/ext/userauth/user-auth.txt sqlite doc.

Sign up to request clarification or add additional context in comments.

3 Comments

i m working on win32c++ nd using #include"sqlite3.h" header file , when i m going to use this function it shows me error that "sqlite3_user_authenticate" is undefined??Can you pls help to get right header file for it.
Activate the user authentication logic by including the ext/userauth/userauth.c source code file in the build and adding the -DSQLITE_USER_AUTHENTICATION compile-time option. The ext/userauth/sqlite3userauth.h header file is available to applications to define the interface.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.