-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecurity.html
159 lines (147 loc) · 5.34 KB
/
security.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Menukaarten-docs</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="assets/css/stylesheet.css" media="screen,print">
<link rel="stylesheet" href="assets/css/print.css" media="print">
<link rel="stylesheet" type="text/css" href="assets/css/shCore.css" media="screen,print">
<link rel="stylesheet" type="text/css" href="assets/css/shThemeDefault.css" media="screen,print">
<script type="text/javascript" src="assets/js/jquery.min.js"></script>
<script type="text/javascript" src="assets/js/SyntaxHighlighter.js"></script>
<script type="text/javascript" src="assets/js/build_menu.js"></script>
</head>
<body>
<div id="header-wrapper">
<div id="header">
<h1>Documentation SexyFramework</h1>
<span>Created by Vincent Bremer & Douwe de Haan</span>
</div>
</div>
<div id="container">
<div id="menu-wrapper">
<div id="menu">
<h1>Table of contents</h1>
<ul></ul>
</div>
</div>
<div id="content-wrapper">
<div id="content">
<!-- START CONTENT -->
<h1>User security</h1>
<h2>Password hashing</h2>
<p>Passwords are that are saved to the database are appended with a security salt. This salt is hard coded in the user model and can only be changed by the technical staff. After adding the salt the password gets encrypted as a SHA1 hash.</p>
Example of the file:
<span class="bold">models/user_model.php</span>
<pre class="brush: php">
private $salt = 'PAwEr&^52sd+=2Y%T';
public function encrypt($password) {
return sha1($this->salt.$password);
}
</pre>
<h2>Login procedure</h2>
To login as a user the following steps has to be performed:<br>
<ul class="list">
<li>Point the web browser to http://restaurantname.menukaarten.nl/login</li>
<li>Enter the login credentials
<ul>
<li>Check if a user with the specified email address exist</li>
<li>Hash the submitted password and compare it with the database</li>
</ul>
</li>
<li>When the credentials are valid:
<ul>
<li>Set the session</li>
<li>Update the last visit date</li>
</ul>
</li>
<li>When the credentials aren't valid:
<ul>
<li>Display an error message (E-mail/password don't match)</li>
</ul>
</li>
</ul>
<h2>Logout procedure</h2>
When the user click on the logout link:<br>
<ul class="list">
<li>The session is being unset</li>
<li>The user get redirected to the base path (homepage)</li>
</ul>
<h2>Forgot password</h2>
When a user has forgotten it’s password there a option at the login page to reset the password. This involves the following actions:<br>
<ul class="list">
<li>A user clicks the Forgot password link</li>
<li>Insert the e-mail address</li>
<li>When the inserted e-mail address is valid
<ul>
<li>Create a unique token</li>
<li>Send the password reset link with to token to the e-mail address</li>
<li>When the user clicks on the link it sees a page with to input fields</li>
<li>Insert the new password twice (to check no mistakes are made)</li>
<li>If the passwords match, save it to the database and login the user</li>
</ul>
</li>
<li>No valid e-mail address inserted, show a message noting that the e-mail address is not valid and stay on the page.</li>
</ul>
<h2>Sessions</h2>
<p>Because all controllers used for the dashboard extend on the Admin_Controller they have access to the session function. When checking if a user is logged in you can use the following function:</p>
<pre class="brush: php">
if ($this->logged_in) {
// user is logged in
}
</pre>
<p>
When a user signs in the following session vars get set:
</p>
<table>
<tr>
<th>var</th>
<th>content</th>
</tr>
<tr>
<td>logged_in</td>
<td>true or false</td>
</tr>
<tr>
<td>firstname</td>
<td>user firstname</td>
</tr>
<tr>
<td>lastname</td>
<td>user lastname</td>
</tr>
<tr>
<td>uid</td>
<td>user id</td>
</tr>
<tr>
<td>role</td>
<td>user role (ex. 100)</td>
</tr>
<tr>
<td>location_id</td>
<td>location of the subdomain the user logs in to.</td>
</tr>
</table>
<h2>User rights/roles</h2>
<p>Different controllers or methods can require a certain minimal role a user has to be. These user rights can be set in the class variable $access. See the following example:</p>
<pre class="brush: php">
protected $access = array(
'default_access' => 100,
'login' => 0,
'logout' => 0,
'forgot_password' => 0,
'reset_password' => 0
);
</pre>
<p>In this example all methods require a user with a role of at least 100. The methods login, logout, forgot_password and reset_password require a role of 0, this means users that aren’t logged in.
When the $access variable is omitted, it defaults to the user role of 1. Which means that all controllers extended on the Admin_Controller are protected so only logged in users can access that methods.</p>
<h2>Changing user settings</h2>
<p>The user role is saved in the session, we’ve done it this way so we don’t have to pull the user from the database on each page. The downside of storing the user role in the session is that it doesn’t get updated when the role is changed in the database. To work around this, the user session gets unset when the roles are changed. This means the user needs to login again when the page get refreshed.</p>
<!-- END CONTENT -->
</div>
</div>
</div>
<script type="text/javascript" src="assets/js/SyntaxHighlighter_settings.js"></script>
</body>
</html>