-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.php
139 lines (112 loc) · 3.32 KB
/
log.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
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
<?php
// Database class for database connection and interaction
class Database
{
private $connection;
public function __construct($hostname, $username, $password, $databaseName)
{
$this->connection = mysqli_connect($hostname, $username, $password, $databaseName);
if (!$this->connection) {
die("Database connection failed: " . mysqli_connect_error());
}
}
public function executeQuery($query)
{
return mysqli_query($this->connection, $query);
}
public function closeConnection()
{
mysqli_close($this->connection);
}
}
// Authentication interface for different authentication strategies
interface AuthenticationStrategy
{
public function authenticate($emailid, $pass1);
}
// AdminAuthentication class implements the AuthenticationStrategy interface
class AdminAuthentication implements AuthenticationStrategy
{
private $db;
public function __construct(Database $database)
{
$this->db = $database;
}
public function authenticate($emailid, $pass1)
{
$query = "SELECT emailid, pass1 FROM admin WHERE emailid='$emailid' and pass1='$pass1'";
$result = $this->db->executeQuery($query);
$count = mysqli_num_rows($result);
if ($count > 0) {
echo "Admin login successful";
exit(header("refresh:1;url=admin.html"));
} else {
echo "Invalid admin login";
exit(header("refresh:1;url=login.html"));
}
}
}
// Iterator Pattern: Basic implementation of Iterator pattern for result set traversal
class ResultSetIterator implements Iterator
{
private $resultSet;
public function __construct($resultSet)
{
$this->resultSet = $resultSet;
}
public function rewind()
{
reset($this->resultSet);
}
public function current()
{
return current($this->resultSet);
}
public function key()
{
return key($this->resultSet);
}
public function next()
{
return next($this->resultSet);
}
public function valid()
{
$key = key($this->resultSet);
return ($key !== null && $key !== false);
}
}
// Decorator Pattern: Basic implementation of Decorator pattern for result set manipulation
class ResultSetDecorator implements Countable
{
private $resultSet;
public function __construct($resultSet)
{
$this->resultSet = $resultSet;
}
public function count()
{
return count($this->resultSet);
}
// Additional decorator methods can be added for result set manipulation
}
// Instantiate the Database class
$db = new Database('localhost', 'root', '', 'uems');
// Instantiate the AdminAuthentication class
$adminAuthentication = new AdminAuthentication($db);
// User input data
$emailid = $_POST['emailid'];
$pass1 = $_POST['pass1'];
// Authenticate using the AdminAuthentication strategy
$resultSet = $adminAuthentication->authenticate($emailid, $pass1);
// Use Iterator to traverse the result set
$iterator = new ResultSetIterator($resultSet);
foreach ($iterator as $row) {
// Process each row
}
// Use Decorator to get the count of the result set
$decoratedResultSet = new ResultSetDecorator($resultSet);
$resultCount = count($decoratedResultSet);
// Close the database connection
$db->closeConnection();
?>