Shivam Sharma
Shivam Sharma

Reputation: 57

How to open password protected db in sqlite3 using c++?

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.

Upvotes: 2

Views: 2009

Answers (1)

kiran Biradar
kiran Biradar

Reputation: 12732

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.

Upvotes: 3

Related Questions