Reputation: 145
I am generating a sqlitedb file with below code
import sqlite3
conn = sqlite3.connect('../sqlitedb/sample_db.db')
Is there any way I can password protect this file or some kind of security in python or generally in windows so nobody can access it.
Upvotes: 0
Views: 4983
Reputation: 4510
Install sqlcipher:
sudo apt-get install sqlcipher
Install sqlcipher package:
pip install pysqlcipher3
Sample Code:
from pysqlcipher3 import dbapi2 as sqlite
conn = sqlite.connect('test.db')
c = conn.cursor()
c.execute("PRAGMA key='password'")
c.execute("PRAGMA cipher_compatibility = 3")
c.execute('''create table stocks (date text, trans text, symbol text, qty real, price real)''')
c.execute("""insert into stocks values ('2006-01-05','BUY','RHAT',100,35.14)""")
conn.commit()
c.close()
Upvotes: 2