-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.php
69 lines (56 loc) · 1.66 KB
/
db.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
// This is really crap, like really crap, but this works for this demo.
// Include this page anytime database access is required.
//$path = realpath(dirname(__FILE__));
$path = "/var/www/ddev.im/projects";
try{
// Connect to the SQLite Database
$db = new PDO("sqlite:$path/passwordDB.sqlite", null, null, array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false
));
}
catch(PDOException $e){
echo $e->getMessage();
}
// Install the Database if required.
if(isset($_GET['action'])){
switch ($_GET['action']){
case "install";
echo "Installing Database...<br />";
dbinstall($db);
break;
case "showTables":
dbShowTables();
break;
default:
echo "Action not found!";
break;
}
}
function dbinstall($db){
// Install the database
// Create the users table
$db->exec("CREATE TABLE IF NOT EXISTS users(
id integer primary key,
username text,
publicKey text,
privateKey text
)");
// Create the passwords table
$db->exec("CREATE TABLE IF NOT EXISTS passwords(
id INTEGER PRIMARY KEY,
title TEXT,
encryptedPass BLOB
)");
// Create the passwordKeys table to store the encryptedKey used to decrypt the password, key is encrypted using users public key
$db->exec("CREATE TABLE IF NOT EXISTS passwordKeys(
passwordID INTEGER,
userID INTEGER,
encryptedKey BLOB
)");
}
function dbShowTables(){
// List all the tables in the database
}