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
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.
3 Comments
Shivam Sharma
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.
kiran Biradar
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.
kiran Biradar
read
user-auth.txt in sqlite.org/src/dir?ci=24b0f66ac611e26f&name=ext/userauth