-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnnection.php
More file actions
164 lines (142 loc) · 4.64 KB
/
Copy pathconnnection.php
File metadata and controls
164 lines (142 loc) · 4.64 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
class connectionmodel
{
private $dsn = "mysql:host=localhost;dbname=pass";
private $user = "root";
private $pass = "";
private $con = null;
private $method = "AES-128-CBC";
private $key = "FCAIH";
private $options = 0;
private $iv = "123456789asdfghj";
private $tag = null;
private $option = array(
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
);
private $users_table = "users";
private $table = "store";
public function getconnection()
{
try {
$this->con = new \PDO($this->dsn, $this->user, $this->pass, $this->option);
$this->con->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
return 0;
}
}
public function closecon()
{
try {
$this->con = null;
} catch (PDOException $e) {
return $e;
}
}
public function checkuser($users, $pass)
{
try {
$stmt = $this->con->prepare("select id, username, password from " . $this->users_table . " where username = ?");
$stmt->execute(array($users));
$row = $stmt->fetch();
if ($this->showPassword($row["password"]) == $pass) {
session_start();
$_SESSION['id'] = $row['id'];
$_SESSION['username'] = $row['username'];
return 1;
}
return 0;
} catch (PDOException $e) {
echo $e;
}
}
public function registeration($user, $pass)
{
try {
$stmt = $this->con->prepare("INSERT INTO $this->users_table (username, password) VALUES (?, ?)");
$encPass = openssl_encrypt($pass, $this->method, $this->key, $this->options, $this->iv);
$stmt->execute(array($user, $encPass));
session_start();
$_SESSION['id'] = $this->con->lastInsertId();
$_SESSION['username'] = $user;
return 1;
} catch (PDOException $e) {
echo $e;
}
}
public function showPassword($pass)
{
try {
return openssl_decrypt($pass, $this->method, $this->key, $this->options, $this->iv);
} catch (Exception $e) {
echo $e;
}
}
public function get_table()
{
try {
$id = $_SESSION["id"];
$stmt = $this->con->prepare("SELECT * FROM `$this->table` WHERE user_id = $id");
$stmt->execute(array());
$row = $stmt->fetchAll();
return $row;
} catch (PDOException $e) {
echo $e;
}
}
public function add_site($site, $pass)
{
try {
$encryptPass = openssl_encrypt($pass, $this->method, $this->key, $this->options, $this->iv);
$stmt = $this->con->prepare("INSERT IGNORE INTO `$this->table` (`site`, `password`, `user_id`) VALUES ( ?, ?, ?)");
$stmt->execute(array($site, $encryptPass, $_SESSION['id']));
$count = $stmt->rowCount();
if ($count > 0) return 1;
else return 0;
} catch (PDOException $e) {
echo $e;
}
}
public function deleteSite($id)
{
try {
$stmt = $this->con->prepare("delete from `$this->table` where id = ?");
$stmt->execute(array($id));
$count = $stmt->rowCount();
if ($count > 0) return 1;
else return 0;
} catch (PDOException $e) {
echo $e;
}
}
public function editSite($id, $site, $pass)
{
try {
$encryptPass = openssl_encrypt($pass, $this->method, $this->key, $this->options, $this->iv);;
$stmt = $this->con->prepare("UPDATE $this->table SET site = ?, password = ? WHERE id = ?");
$stmt->execute(array($site, $encryptPass, $id));
$count = $stmt->rowCount();
if ($count > 0) return 1;
else return 0;
} catch (PDOException $e) {
echo $e;
}
}
public function checkAdmin() {
try {
$id = $_SESSION["id"];
$stmt = $this->con->prepare("SELECT 'admin' FROM `$this->users_table` WHERE id = $id");
$stmt->execute(array());
$row = $stmt->fetch();
if ($row["admin"] == 1) return true;
else return false;
} catch (PDOException $e) {
echo $e;
}
}
public function getAllUsers() {
$stmt = $this->con->prepare("SELECT * FROM `$this->users_table`");
$stmt->execute(array());
$rows = $stmt->fetchAll();
return $rows;
}
}