-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataBase.php
More file actions
72 lines (63 loc) · 2.21 KB
/
DataBase.php
File metadata and controls
72 lines (63 loc) · 2.21 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
<?php
require "DataBaseConfig.php";
class DataBase
{
public $connect;
public $data;
private $sql;
protected $servername;
protected $username;
protected $password;
protected $databasename;
public function __construct()
{
$this->connect = null;
$this->data = null;
$this->sql = null;
$dbc = new DataBaseConfig();
$this->servername = $dbc->servername;
$this->username = $dbc->username;
$this->password = $dbc->password;
$this->databasename = $dbc->databasename;
}
function dbConnect()
{
$this->connect = mysqli_connect($this->servername, $this->username, $this->password, $this->databasename);
echo "jesica";
return $this->connect;
}
function prepareData($data)
{
return mysqli_real_escape_string($this->connect, stripslashes(htmlspecialchars($data)));
}
function logIn($table, $username, $password)
{
$username = $this->prepareData($username);
$password = $this->prepareData($password);
$this->sql = "select * from " . $table . " where username = '" . $username . "'";
$result = mysqli_query($this->connect, $this->sql);
$row = mysqli_fetch_assoc($result);
if (mysqli_num_rows($result) != 0) {
$dbusername = $row['username'];
$dbpassword = $row['password'];
if ($dbusername == $username && password_verify($password, $dbpassword)) {
$login = true;
} else $login = false;
} else $login = false;
return $login;
}
function signUp($table, $fullname, $email, $username, $password)
{
$fullname = $this->prepareData($fullname);
$username = $this->prepareData($username);
$password = $this->prepareData($password);
$email = $this->prepareData($email);
$password = password_hash($password, PASSWORD_DEFAULT);
$this->sql =
"INSERT INTO " . $table . " (fullname, username, password, email) VALUES ('" . $fullname . "','" . $username . "','" . $password . "','" . $email . "')";
if (mysqli_query($this->connect, $this->sql)) {
return true;
} else return false;
}
}
?>