GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( e54387...b62a26 )
by Lonnie
10s
created
myth/Api/Server/LogModel.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -55,11 +55,11 @@
 block discarded – undo
55 55
 		$time = date('Y-m-d H:00:00');
56 56
 
57 57
 		$query = $this->db->select('id')
58
-						  ->where('user_id', (int)$user_id)
58
+						  ->where('user_id', (int) $user_id)
59 59
 						  ->where('created_on >=', $time)
60 60
 						  ->get($this->table_name);
61 61
 
62
-		return (int)$query->num_rows();
62
+		return (int) $query->num_rows();
63 63
 	}
64 64
 
65 65
 	//--------------------------------------------------------------------
Please login to merge, or discard this patch.
myth/Auth/AuthenticateInterface.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      * @param $credentials
52 52
      * @param bool $remember
53 53
      */
54
-    public function login($credentials, $remember=false);
54
+    public function login($credentials, $remember = false);
55 55
 
56 56
     //--------------------------------------------------------------------
57 57
 
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
      * @param bool $return_user
66 66
      * @return mixed
67 67
      */
68
-    public function validate($credentials, $return_user=false);
68
+    public function validate($credentials, $return_user = false);
69 69
 
70 70
     //--------------------------------------------------------------------
71 71
 
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
      * @param null $message
189 189
      * @return mixed
190 190
      */
191
-    public function changeStatus($newStatus, $message=null);
191
+    public function changeStatus($newStatus, $message = null);
192 192
 
193 193
     //--------------------------------------------------------------------
194 194
 
Please login to merge, or discard this patch.
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -42,197 +42,197 @@
 block discarded – undo
42 42
  */
43 43
 interface AuthenticateInterface {
44 44
 
45
-    /**
46
-     * Attempt to log a user into the system.
47
-     *
48
-     * $credentials is an array of key/value pairs needed to log the user in.
49
-     * This is often email/password, or username/password.
50
-     *
51
-     * @param $credentials
52
-     * @param bool $remember
53
-     */
54
-    public function login($credentials, $remember=false);
55
-
56
-    //--------------------------------------------------------------------
57
-
58
-    /**
59
-     * Validates user login information without logging them in.
60
-     *
61
-     * $credentials is an array of key/value pairs needed to log the user in.
62
-     * This is often email/password, or username/password.
63
-     *
64
-     * @param $credentials
65
-     * @param bool $return_user
66
-     * @return mixed
67
-     */
68
-    public function validate($credentials, $return_user=false);
69
-
70
-    //--------------------------------------------------------------------
71
-
72
-    /**
73
-     * Logs a user out and removes all session information.
74
-     *
75
-     * @return mixed
76
-     */
77
-    public function logout();
78
-
79
-    //--------------------------------------------------------------------
80
-
81
-    /**
82
-     * Checks whether a user is logged in or not.
83
-     *
84
-     * @return bool
85
-     */
86
-    public function isLoggedIn();
87
-
88
-    //--------------------------------------------------------------------
89
-
90
-    /**
91
-     * Attempts to log a user in based on the "remember me" cookie.
92
-     *
93
-     * @return bool
94
-     */
95
-    public function viaRemember();
96
-
97
-    //--------------------------------------------------------------------
98
-
99
-    /**
100
-     * Registers a new user and handles activation method.
101
-     *
102
-     * @param $user_data
103
-     * @return bool
104
-     */
105
-    public function registerUser($user_data);
106
-
107
-    //--------------------------------------------------------------------
108
-
109
-    /**
110
-     * Used to verify the user values and activate a user so they can
111
-     * visit the site.
112
-     *
113
-     * @param $data
114
-     * @return bool
115
-     */
116
-    public function activateUser($data);
117
-
118
-    //--------------------------------------------------------------------
119
-
120
-    /**
121
-     * Used to allow manual activation of a user with a known ID.
122
-     *
123
-     * @param $id
124
-     * @return bool
125
-     */
126
-    public function activateUserById($id);
127
-
128
-    //--------------------------------------------------------------------
129
-
130
-    /**
131
-     * Grabs the current user object. Returns NULL if nothing found.
132
-     *
133
-     * @return array|null
134
-     */
135
-    public function user();
136
-
137
-    //--------------------------------------------------------------------
138
-
139
-    /**
140
-     * A convenience method to grab the current user's ID.
141
-     *
142
-     * @return int|null
143
-     */
144
-    public function id();
145
-
146
-    //--------------------------------------------------------------------
147
-
148
-    /**
149
-     * Tells the system to start throttling a user. This may vary by implementation,
150
-     * but will often add additional time before another login is allowed.
151
-     *
152
-     * @param $email
153
-     * @return mixed
154
-     */
155
-    public function isThrottled($email);
156
-
157
-    //--------------------------------------------------------------------
158
-
159
-    /**
160
-     * Sends a password reminder email to the user associated with
161
-     * the passed in $email.
162
-     *
163
-     * @param $email
164
-     * @return mixed
165
-     */
166
-    public function remindUser($email);
167
-
168
-    //--------------------------------------------------------------------
169
-
170
-    /**
171
-     * Validates the credentials provided and, if valid, resets the password.
172
-     *
173
-     * @param $credentials
174
-     * @param $password
175
-     * @param $passConfirm
176
-     * @return mixed
177
-     */
178
-    public function resetPassword($credentials, $password, $passConfirm);
179
-
180
-    //--------------------------------------------------------------------
181
-
182
-    /**
183
-     * Provides a way for implementations to allow new statuses to be set
184
-     * on the user. The details will vary based upon implementation, but
185
-     * will often allow for banning or suspending users.
186
-     *
187
-     * @param $newStatus
188
-     * @param null $message
189
-     * @return mixed
190
-     */
191
-    public function changeStatus($newStatus, $message=null);
192
-
193
-    //--------------------------------------------------------------------
194
-
195
-    /**
196
-     * Allows the consuming application to pass in a reference to the
197
-     * model that should be used.
198
-     *
199
-     * The model MUST extend Myth\Models\CIDbModel.
200
-     *
201
-     * @param $model
202
-     * @return mixed
203
-     */
204
-    public function useModel($model);
205
-
206
-    //--------------------------------------------------------------------
207
-
208
-    /**
209
-     * Returns the current error string.
210
-     *
211
-     * @return mixed
212
-     */
213
-    public function error();
214
-
215
-    //--------------------------------------------------------------------
216
-
217
-    /**
218
-     * Purges all login attempt records from the database.
219
-     *
220
-     * @param null $ip_address
221
-     * @param null $user_id
222
-     */
223
-    public function purgeLoginAttempts($ip_address = null, $user_id = null);
224
-
225
-    //--------------------------------------------------------------------
226
-
227
-    /**
228
-     * Purges all remember tokens for a single user. Effectively logs
229
-     * a user out of all devices. Intended to allow users to log themselves
230
-     * out of all devices as a security measure.
231
-     *
232
-     * @param $email
233
-     */
234
-    public function purgeRememberTokens($email);
235
-
236
-    //--------------------------------------------------------------------
45
+	/**
46
+	 * Attempt to log a user into the system.
47
+	 *
48
+	 * $credentials is an array of key/value pairs needed to log the user in.
49
+	 * This is often email/password, or username/password.
50
+	 *
51
+	 * @param $credentials
52
+	 * @param bool $remember
53
+	 */
54
+	public function login($credentials, $remember=false);
55
+
56
+	//--------------------------------------------------------------------
57
+
58
+	/**
59
+	 * Validates user login information without logging them in.
60
+	 *
61
+	 * $credentials is an array of key/value pairs needed to log the user in.
62
+	 * This is often email/password, or username/password.
63
+	 *
64
+	 * @param $credentials
65
+	 * @param bool $return_user
66
+	 * @return mixed
67
+	 */
68
+	public function validate($credentials, $return_user=false);
69
+
70
+	//--------------------------------------------------------------------
71
+
72
+	/**
73
+	 * Logs a user out and removes all session information.
74
+	 *
75
+	 * @return mixed
76
+	 */
77
+	public function logout();
78
+
79
+	//--------------------------------------------------------------------
80
+
81
+	/**
82
+	 * Checks whether a user is logged in or not.
83
+	 *
84
+	 * @return bool
85
+	 */
86
+	public function isLoggedIn();
87
+
88
+	//--------------------------------------------------------------------
89
+
90
+	/**
91
+	 * Attempts to log a user in based on the "remember me" cookie.
92
+	 *
93
+	 * @return bool
94
+	 */
95
+	public function viaRemember();
96
+
97
+	//--------------------------------------------------------------------
98
+
99
+	/**
100
+	 * Registers a new user and handles activation method.
101
+	 *
102
+	 * @param $user_data
103
+	 * @return bool
104
+	 */
105
+	public function registerUser($user_data);
106
+
107
+	//--------------------------------------------------------------------
108
+
109
+	/**
110
+	 * Used to verify the user values and activate a user so they can
111
+	 * visit the site.
112
+	 *
113
+	 * @param $data
114
+	 * @return bool
115
+	 */
116
+	public function activateUser($data);
117
+
118
+	//--------------------------------------------------------------------
119
+
120
+	/**
121
+	 * Used to allow manual activation of a user with a known ID.
122
+	 *
123
+	 * @param $id
124
+	 * @return bool
125
+	 */
126
+	public function activateUserById($id);
127
+
128
+	//--------------------------------------------------------------------
129
+
130
+	/**
131
+	 * Grabs the current user object. Returns NULL if nothing found.
132
+	 *
133
+	 * @return array|null
134
+	 */
135
+	public function user();
136
+
137
+	//--------------------------------------------------------------------
138
+
139
+	/**
140
+	 * A convenience method to grab the current user's ID.
141
+	 *
142
+	 * @return int|null
143
+	 */
144
+	public function id();
145
+
146
+	//--------------------------------------------------------------------
147
+
148
+	/**
149
+	 * Tells the system to start throttling a user. This may vary by implementation,
150
+	 * but will often add additional time before another login is allowed.
151
+	 *
152
+	 * @param $email
153
+	 * @return mixed
154
+	 */
155
+	public function isThrottled($email);
156
+
157
+	//--------------------------------------------------------------------
158
+
159
+	/**
160
+	 * Sends a password reminder email to the user associated with
161
+	 * the passed in $email.
162
+	 *
163
+	 * @param $email
164
+	 * @return mixed
165
+	 */
166
+	public function remindUser($email);
167
+
168
+	//--------------------------------------------------------------------
169
+
170
+	/**
171
+	 * Validates the credentials provided and, if valid, resets the password.
172
+	 *
173
+	 * @param $credentials
174
+	 * @param $password
175
+	 * @param $passConfirm
176
+	 * @return mixed
177
+	 */
178
+	public function resetPassword($credentials, $password, $passConfirm);
179
+
180
+	//--------------------------------------------------------------------
181
+
182
+	/**
183
+	 * Provides a way for implementations to allow new statuses to be set
184
+	 * on the user. The details will vary based upon implementation, but
185
+	 * will often allow for banning or suspending users.
186
+	 *
187
+	 * @param $newStatus
188
+	 * @param null $message
189
+	 * @return mixed
190
+	 */
191
+	public function changeStatus($newStatus, $message=null);
192
+
193
+	//--------------------------------------------------------------------
194
+
195
+	/**
196
+	 * Allows the consuming application to pass in a reference to the
197
+	 * model that should be used.
198
+	 *
199
+	 * The model MUST extend Myth\Models\CIDbModel.
200
+	 *
201
+	 * @param $model
202
+	 * @return mixed
203
+	 */
204
+	public function useModel($model);
205
+
206
+	//--------------------------------------------------------------------
207
+
208
+	/**
209
+	 * Returns the current error string.
210
+	 *
211
+	 * @return mixed
212
+	 */
213
+	public function error();
214
+
215
+	//--------------------------------------------------------------------
216
+
217
+	/**
218
+	 * Purges all login attempt records from the database.
219
+	 *
220
+	 * @param null $ip_address
221
+	 * @param null $user_id
222
+	 */
223
+	public function purgeLoginAttempts($ip_address = null, $user_id = null);
224
+
225
+	//--------------------------------------------------------------------
226
+
227
+	/**
228
+	 * Purges all remember tokens for a single user. Effectively logs
229
+	 * a user out of all devices. Intended to allow users to log themselves
230
+	 * out of all devices as a security measure.
231
+	 *
232
+	 * @param $email
233
+	 */
234
+	public function purgeRememberTokens($email);
235
+
236
+	//--------------------------------------------------------------------
237 237
 
238 238
 }
Please login to merge, or discard this patch.
myth/Auth/AuthorizeInterface.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
  * @since       Version 1.0
31 31
  */
32 32
 
33
-interface AuthorizeInterface  {
33
+interface AuthorizeInterface {
34 34
 
35 35
 	/**
36 36
 	 * Returns the latest error string.
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	 *
151 151
 	 * @return mixed
152 152
 	 */
153
-	public function createGroup($name, $description='');
153
+	public function createGroup($name, $description = '');
154 154
 
155 155
 	//--------------------------------------------------------------------
156 156
 
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 	 *
175 175
 	 * @return mixed
176 176
 	 */
177
-	public function updateGroup($id, $name, $description='');
177
+	public function updateGroup($id, $name, $description = '');
178 178
 
179 179
 	//--------------------------------------------------------------------
180 180
 
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 	 *
211 211
 	 * @return mixed
212 212
 	 */
213
-	public function createPermission($name, $description='');
213
+	public function createPermission($name, $description = '');
214 214
 
215 215
 	//--------------------------------------------------------------------
216 216
 
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 	 *
235 235
 	 * @return bool
236 236
 	 */
237
-	public function updatePermission($id, $name, $description='');
237
+	public function updatePermission($id, $name, $description = '');
238 238
 
239 239
 	//--------------------------------------------------------------------
240 240
 
Please login to merge, or discard this patch.
myth/Auth/Flat/FlatGroupsModel.php 2 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -85,10 +85,10 @@  discard block
 block discarded – undo
85 85
 	 */
86 86
 	public function addUserToGroup($user_id, $group_id)
87 87
 	{
88
-	    $data = [
89
-		    'user_id'   => (int)$user_id,
90
-		    'group_id'  => (int)$group_id
91
-	    ];
88
+		$data = [
89
+			'user_id'   => (int)$user_id,
90
+			'group_id'  => (int)$group_id
91
+		];
92 92
 
93 93
 		return $this->db->insert('auth_groups_users', $data);
94 94
 	}
@@ -105,10 +105,10 @@  discard block
 block discarded – undo
105 105
 	 */
106 106
 	public function removeUserFromGroup($user_id, $group_id)
107 107
 	{
108
-	    return $this->where([
109
-		    'user_id' => (int)$user_id,
110
-		    'group_id' => (int)$group_id
111
-	    ])->delete('auth_groups_users');
108
+		return $this->where([
109
+			'user_id' => (int)$user_id,
110
+			'group_id' => (int)$group_id
111
+		])->delete('auth_groups_users');
112 112
 	}
113 113
 
114 114
 	//--------------------------------------------------------------------
@@ -122,8 +122,8 @@  discard block
 block discarded – undo
122 122
 	 */
123 123
 	public function removeUserFromAllGroups($user_id)
124 124
 	{
125
-	    return $this->db->where('user_id', (int)$user_id)
126
-		                ->delete('auth_groups_users');
125
+		return $this->db->where('user_id', (int)$user_id)
126
+						->delete('auth_groups_users');
127 127
 	}
128 128
 
129 129
 	//--------------------------------------------------------------------
@@ -137,11 +137,11 @@  discard block
 block discarded – undo
137 137
 	 */
138 138
 	public function getGroupsForUser($user_id)
139 139
 	{
140
-	    return $this->select('auth_groups_users.*, auth_groups.name, auth_groups.description')
141
-		            ->join('auth_groups_users', 'auth_groups_users.group_id = auth_groups.id', 'left')
142
-		            ->where('user_id', $user_id)
143
-		            ->as_array()
144
-		            ->find_all();
140
+		return $this->select('auth_groups_users.*, auth_groups.name, auth_groups.description')
141
+					->join('auth_groups_users', 'auth_groups_users.group_id = auth_groups.id', 'left')
142
+					->where('user_id', $user_id)
143
+					->as_array()
144
+					->find_all();
145 145
 	}
146 146
 
147 147
 	//--------------------------------------------------------------------
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 			'group_id'      => (int)$group_id
161 161
 		];
162 162
 
163
-	    return $this->db->insert('auth_groups_permissions', $data);
163
+		return $this->db->insert('auth_groups_permissions', $data);
164 164
 	}
165 165
 
166 166
 	//--------------------------------------------------------------------
@@ -176,10 +176,10 @@  discard block
 block discarded – undo
176 176
 	 */
177 177
 	public function removePermissionFromGroup($permission_id, $group_id)
178 178
 	{
179
-	    return $this->db->where([
180
-		    'permission_id' => $permission_id,
181
-		    'group_id'      => $group_id
182
-	    ])->delete('auth_groups_permissions');
179
+		return $this->db->where([
180
+			'permission_id' => $permission_id,
181
+			'group_id'      => $group_id
182
+		])->delete('auth_groups_permissions');
183 183
 	}
184 184
 
185 185
 	//--------------------------------------------------------------------
@@ -193,8 +193,8 @@  discard block
 block discarded – undo
193 193
 	 */
194 194
 	public function removePermissionFromAllGroups($permission_id)
195 195
 	{
196
-	    return $this->db->where('permission_id', $permission_id)
197
-		                ->delete('auth_groups_permissions');
196
+		return $this->db->where('permission_id', $permission_id)
197
+						->delete('auth_groups_permissions');
198 198
 	}
199 199
 
200 200
 	//--------------------------------------------------------------------
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -86,8 +86,8 @@  discard block
 block discarded – undo
86 86
 	public function addUserToGroup($user_id, $group_id)
87 87
 	{
88 88
 	    $data = [
89
-		    'user_id'   => (int)$user_id,
90
-		    'group_id'  => (int)$group_id
89
+		    'user_id'   => (int) $user_id,
90
+		    'group_id'  => (int) $group_id
91 91
 	    ];
92 92
 
93 93
 		return $this->db->insert('auth_groups_users', $data);
@@ -106,8 +106,8 @@  discard block
 block discarded – undo
106 106
 	public function removeUserFromGroup($user_id, $group_id)
107 107
 	{
108 108
 	    return $this->where([
109
-		    'user_id' => (int)$user_id,
110
-		    'group_id' => (int)$group_id
109
+		    'user_id' => (int) $user_id,
110
+		    'group_id' => (int) $group_id
111 111
 	    ])->delete('auth_groups_users');
112 112
 	}
113 113
 
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	 */
123 123
 	public function removeUserFromAllGroups($user_id)
124 124
 	{
125
-	    return $this->db->where('user_id', (int)$user_id)
125
+	    return $this->db->where('user_id', (int) $user_id)
126 126
 		                ->delete('auth_groups_users');
127 127
 	}
128 128
 
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
 	public function addPermissionToGroup($permission_id, $group_id)
157 157
 	{
158 158
 		$data = [
159
-			'permission_id' => (int)$permission_id,
160
-			'group_id'      => (int)$group_id
159
+			'permission_id' => (int) $permission_id,
160
+			'group_id'      => (int) $group_id
161 161
 		];
162 162
 
163 163
 	    return $this->db->insert('auth_groups_permissions', $data);
Please login to merge, or discard this patch.
myth/Auth/Flat/FlatPermissionsModel.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -84,11 +84,11 @@
 block discarded – undo
84 84
 	{
85 85
 		$permissions = $this->join('auth_groups_permissions', 'auth_groups_permissions.permission_id = auth_permissions.id', 'inner')
86 86
 							->join('auth_groups_users', 'auth_groups_users.group_id = auth_groups_permissions.group_id', 'inner')
87
-							->where('auth_groups_users.user_id', (int)$user_id)
87
+							->where('auth_groups_users.user_id', (int) $user_id)
88 88
 							->as_array()
89 89
 							->find_all();
90 90
 
91
-		if (! $permissions)
91
+		if ( ! $permissions)
92 92
 		{
93 93
 			return false;
94 94
 		}
Please login to merge, or discard this patch.
myth/Auth/Password.php 3 patches
Indentation   +321 added lines, -321 removed lines patch added patch discarded remove patch
@@ -51,325 +51,325 @@
 block discarded – undo
51 51
  */
52 52
 class Password {
53 53
 
54
-    /**
55
-     * A standardized method for hasing a password before storing
56
-     * in the database.
57
-     *
58
-     * @param $password
59
-     * @return bool|mixed|string
60
-     */
61
-    public static function hashPassword($password)
62
-    {
63
-        if (! config_item('auth.hash_cost'))
64
-        {
65
-            get_instance()->load->config('auth');
66
-        }
67
-
68
-        return password_hash($password, PASSWORD_DEFAULT, ['cost' => config_item('auth.hash_cost')]);
69
-    }
70
-
71
-    //--------------------------------------------------------------------
72
-
73
-    /**
74
-     * Determines the number of entropy bits a password has based on
75
-     *
76
-     *
77
-     * @param $password
78
-     * @param bool $repeatcalc
79
-     * @return int
80
-     */
81
-    public static function getNISTNumBits($password, $repeatcalc = false)
82
-    {
83
-        $y = strlen($password);
84
-        if ($repeatcalc)
85
-        {
86
-            // Variant on NIST rules to reduce long sequences of repeated characters.
87
-            $result = 0;
88
-            $charmult = array_fill(0, 256, 1);
89
-            for ($x = 0; $x < $y; $x++)
90
-            {
91
-                $tempchr = ord(substr($password, $x, 1));
92
-                if ($x > 19)  $result += $charmult[$tempchr];
93
-                else if ($x > 7)  $result += $charmult[$tempchr] * 1.5;
94
-                else if ($x > 0)  $result += $charmult[$tempchr] * 2;
95
-                else  $result += 4;
96
-
97
-                $charmult[$tempchr] *= 0.75;
98
-            }
99
-
100
-            return $result;
101
-        }
102
-        else
103
-        {
104
-            if ($y > 20)  return 4 + (7 * 2) + (12 * 1.5) + $y - 20;
105
-            if ($y > 8)  return 4 + (7 * 2) + (($y - 8) * 1.5);
106
-            if ($y > 1)  return 4 + (($y - 1) * 2);
107
-
108
-            return ($y == 1 ? 4 : 0);
109
-        }
110
-    }
111
-
112
-    //--------------------------------------------------------------------
113
-
114
-    /**
115
-     * Determines whether a password is strong enough to use. You should check
116
-     * the password against this method and reject it if the password is not
117
-     * strong enough.
118
-     *
119
-     * The following guidelines come from the author's tests against 10.4 million actual passwords
120
-     * ( see post: http://cubicspot.blogspot.com/2012/01/how-to-calculate-password-strength-part.html )
121
-     * and represents the suggested minimum entropy bits for different types of sites:
122
-     *
123
-     *      - 18 bits of entropy = minimum for ANY website.
124
-     *      - 25 bits of entropy = minimum for a general purpose web service used relatively widely (e.g. Hotmail).
125
-     *      - 30 bits of entropy = minimum for a web service with business critical applications (e.g. SAAS).
126
-     *      - 40 bits of entropy = minimum for a bank or other financial service.
127
-     *
128
-     * The algorithm is based upon a modified version of the NIST rules which suggest the following:
129
-     *
130
-     *      - The first byte counts as 4 bits.
131
-     *      - The next 7 bytes count as 2 bits each.
132
-     *      - The next 12 bytes count as 1.5 bits each.
133
-     *      - Anything beyond that counts as 1 bit each.
134
-     *      - Mixed case + non-alphanumeric = up to 6 extra bits.
135
-     *
136
-     * @param string    $password   - The password to check
137
-     * @param int       $minbits    - Minimum "entropy bits" that is allowed
138
-     * @param bool      $usedict    - Should we check the password against a 300,000 word English dictionary?
139
-     * @param int       $minwordlen -
140
-     * @return bool
141
-     */
142
-    public static function isStrongPassword($password, $minbits = 18, $usedict = false, $minwordlen = 4)
143
-    {
144
-        // NIST password strength rules allow up to 6 extra bits for mixed case and non-alphabetic.
145
-        $upper = false;
146
-        $lower = false;
147
-        $numeric = false;
148
-        $other = false;
149
-        $space = false;
150
-        $y = strlen($password);
151
-        for ($x = 0; $x < $y; $x++)
152
-        {
153
-            $tempchr = ord(substr($password, $x, 1));
154
-            if ($tempchr >= ord("A") && $tempchr <= ord("Z"))  $upper = true;
155
-            else if ($tempchr >= ord("a") && $tempchr <= ord("z"))  $lower = true;
156
-            else if ($tempchr >= ord("0") && $tempchr <= ord("9"))  $numeric = true;
157
-            else if ($tempchr == ord(" "))  $space = true;
158
-            else  $other = true;
159
-        }
160
-        $extrabits = ($upper && $lower && $other ? ($numeric ? 6 : 5) : ($numeric && !$upper && !$lower ? ($other ? -2 : -6) : 0));
161
-        if (!$space)  $extrabits -= 2;
162
-        else if (count(explode(" ", preg_replace('/\s+/', " ", $password))) > 3)  $extrabits++;
163
-        $result = self::getNISTNumBits($password, true) + $extrabits;
164
-
165
-        $password = strtolower($password);
166
-        $revpassword = strrev($password);
167
-        $numbits = self::getNISTNumBits($password) + $extrabits;
168
-        if ($result > $numbits)  $result = $numbits;
169
-
170
-        // Remove QWERTY strings.
171
-        $qwertystrs = array(
172
-            "1234567890-qwertyuiopasdfghjkl;zxcvbnm,./",
173
-            "1qaz2wsx3edc4rfv5tgb6yhn7ujm8ik,9ol.0p;/-['=]:?_{\"+}",
174
-            "1qaz2wsx3edc4rfv5tgb6yhn7ujm8ik9ol0p",
175
-            "qazwsxedcrfvtgbyhnujmik,ol.p;/-['=]:?_{\"+}",
176
-            "qazwsxedcrfvtgbyhnujmikolp",
177
-            "]\"/=[;.-pl,0okm9ijn8uhb7ygv6tfc5rdx4esz3wa2q1",
178
-            "pl0okm9ijn8uhb7ygv6tfc5rdx4esz3wa2q1",
179
-            "]\"/[;.pl,okmijnuhbygvtfcrdxeszwaq",
180
-            "plokmijnuhbygvtfcrdxeszwaq",
181
-            "014725836914702583697894561230258/369*+-*/",
182
-            "abcdefghijklmnopqrstuvwxyz"
183
-        );
184
-        foreach ($qwertystrs as $qwertystr)
185
-        {
186
-            $qpassword = $password;
187
-            $qrevpassword = $revpassword;
188
-            $z = 6;
189
-            do
190
-            {
191
-                $y = strlen($qwertystr) - $z;
192
-                for ($x = 0; $x < $y; $x++)
193
-                {
194
-                    $str = substr($qwertystr, $x, $z);
195
-                    $qpassword = str_replace($str, "*", $qpassword);
196
-                    $qrevpassword = str_replace($str, "*", $qrevpassword);
197
-                }
198
-
199
-                $z--;
200
-            } while ($z > 2);
201
-
202
-            $numbits = self::getNISTNumBits($qpassword) + $extrabits;
203
-            if ($result > $numbits)  $result = $numbits;
204
-            $numbits = self::getNISTNumBits($qrevpassword) + $extrabits;
205
-            if ($result > $numbits)  $result = $numbits;
206
-
207
-            if ($result < $minbits)  return false;
208
-        }
209
-
210
-        if ($usedict && $result >= $minbits)
211
-        {
212
-            $passwords = array();
213
-
214
-            // Add keyboard shifting password variants.
215
-            $keyboardmap_down_noshift = array(
216
-                "z" => "", "x" => "", "c" => "", "v" => "", "b" => "", "n" => "", "m" => "", "," => "", "." => "", "/" => "", "<" => "", ">" => "", "?" => ""
217
-            );
218
-            if ($password == str_replace(array_keys($keyboardmap_down_noshift), array_values($keyboardmap_down_noshift), $password))
219
-            {
220
-                $keyboardmap_downright = array(
221
-                    "a" => "z",
222
-                    "q" => "a",
223
-                    "1" => "q",
224
-                    "s" => "x",
225
-                    "w" => "s",
226
-                    "2" => "w",
227
-                    "d" => "c",
228
-                    "e" => "d",
229
-                    "3" => "e",
230
-                    "f" => "v",
231
-                    "r" => "f",
232
-                    "4" => "r",
233
-                    "g" => "b",
234
-                    "t" => "g",
235
-                    "5" => "t",
236
-                    "h" => "n",
237
-                    "y" => "h",
238
-                    "6" => "y",
239
-                    "j" => "m",
240
-                    "u" => "j",
241
-                    "7" => "u",
242
-                    "i" => "k",
243
-                    "8" => "i",
244
-                    "o" => "l",
245
-                    "9" => "o",
246
-                    "0" => "p",
247
-                );
248
-
249
-                $keyboardmap_downleft = array(
250
-                    "2" => "q",
251
-                    "w" => "a",
252
-                    "3" => "w",
253
-                    "s" => "z",
254
-                    "e" => "s",
255
-                    "4" => "e",
256
-                    "d" => "x",
257
-                    "r" => "d",
258
-                    "5" => "r",
259
-                    "f" => "c",
260
-                    "t" => "f",
261
-                    "6" => "t",
262
-                    "g" => "v",
263
-                    "y" => "g",
264
-                    "7" => "y",
265
-                    "h" => "b",
266
-                    "u" => "h",
267
-                    "8" => "u",
268
-                    "j" => "n",
269
-                    "i" => "j",
270
-                    "9" => "i",
271
-                    "k" => "m",
272
-                    "o" => "k",
273
-                    "0" => "o",
274
-                    "p" => "l",
275
-                    "-" => "p",
276
-                );
277
-
278
-                $password2 = str_replace(array_keys($keyboardmap_downright), array_values($keyboardmap_downright), $password);
279
-                $passwords[] = $password2;
280
-                $passwords[] = strrev($password2);
281
-
282
-                $password2 = str_replace(array_keys($keyboardmap_downleft), array_values($keyboardmap_downleft), $password);
283
-                $passwords[] = $password2;
284
-                $passwords[] = strrev($password2);
285
-            }
286
-
287
-            // Deal with LEET-Speak substitutions.
288
-            $leetspeakmap = array(
289
-                "@" => "a",
290
-                "!" => "i",
291
-                "$" => "s",
292
-                "1" => "i",
293
-                "2" => "z",
294
-                "3" => "e",
295
-                "4" => "a",
296
-                "5" => "s",
297
-                "6" => "g",
298
-                "7" => "t",
299
-                "8" => "b",
300
-                "9" => "g",
301
-                "0" => "o"
302
-            );
303
-
304
-            $password2 = str_replace(array_keys($leetspeakmap), array_values($leetspeakmap), $password);
305
-            $passwords[] = $password2;
306
-            $passwords[] = strrev($password2);
307
-
308
-            $leetspeakmap["1"] = "l";
309
-            $password3 = str_replace(array_keys($leetspeakmap), array_values($leetspeakmap), $password);
310
-            if ($password3 != $password2)
311
-            {
312
-                $passwords[] = $password3;
313
-                $passwords[] = strrev($password3);
314
-            }
315
-
316
-            // Process the password, while looking for words in the dictionary.
317
-            $a = ord("a");
318
-            $z = ord("z");
319
-            $data = file_get_contents(DICTIONARY_PATH);
320
-            foreach ($passwords as $num => $password)
321
-            {
322
-                $y = strlen($password);
323
-                for ($x = 0; $x < $y; $x++)
324
-                {
325
-                    $tempchr = ord(substr($password, $x, 1));
326
-                    if ($tempchr >= $a && $tempchr <= $z)
327
-                    {
328
-                        for ($x2 = $x + 1; $x2 < $y; $x2++)
329
-                        {
330
-                            $tempchr = ord(substr($password, $x2, 1));
331
-                            if ($tempchr < $a || $tempchr > $z)  break;
332
-                        }
333
-
334
-                        $found = false;
335
-                        while (!$found && $x2 - $x >= $minwordlen)
336
-                        {
337
-                            $word = "/\\n" . substr($password, $x, $minwordlen);
338
-                            for ($x3 = $x + $minwordlen; $x3 < $x2; $x3++)  $word .= "(" . $password{$x3};
339
-                            for ($x3 = $x + $minwordlen; $x3 < $x2; $x3++)  $word .= ")?";
340
-                            $word .= "\\n/";
341
-
342
-                            preg_match_all($word, $data, $matches);
343
-                            if (!count($matches[0]))
344
-                            {
345
-                                $password{$x} = "*";
346
-                                $x++;
347
-                                $numbits = self::getNISTNumBits(substr($password, 0, $x)) + $extrabits;
348
-                                if ($numbits >= $minbits)  $found = true;
349
-                            }
350
-                            else
351
-                            {
352
-                                foreach ($matches[0] as $match)
353
-                                {
354
-                                    $password2 = str_replace(trim($match), "*", $password);
355
-                                    $numbits = self::getNISTNumBits($password2) + $extrabits;
356
-                                    if ($result > $numbits)  $result = $numbits;
357
-
358
-                                    if ($result < $minbits)  return false;
359
-                                }
360
-
361
-                                $found = true;
362
-                            }
363
-                        }
364
-
365
-                        if ($found)  break;
366
-
367
-                        $x = $x2 - 1;
368
-                    }
369
-                }
370
-            }
371
-        }
372
-
373
-        return $result >= $minbits;
374
-    }
54
+	/**
55
+	 * A standardized method for hasing a password before storing
56
+	 * in the database.
57
+	 *
58
+	 * @param $password
59
+	 * @return bool|mixed|string
60
+	 */
61
+	public static function hashPassword($password)
62
+	{
63
+		if (! config_item('auth.hash_cost'))
64
+		{
65
+			get_instance()->load->config('auth');
66
+		}
67
+
68
+		return password_hash($password, PASSWORD_DEFAULT, ['cost' => config_item('auth.hash_cost')]);
69
+	}
70
+
71
+	//--------------------------------------------------------------------
72
+
73
+	/**
74
+	 * Determines the number of entropy bits a password has based on
75
+	 *
76
+	 *
77
+	 * @param $password
78
+	 * @param bool $repeatcalc
79
+	 * @return int
80
+	 */
81
+	public static function getNISTNumBits($password, $repeatcalc = false)
82
+	{
83
+		$y = strlen($password);
84
+		if ($repeatcalc)
85
+		{
86
+			// Variant on NIST rules to reduce long sequences of repeated characters.
87
+			$result = 0;
88
+			$charmult = array_fill(0, 256, 1);
89
+			for ($x = 0; $x < $y; $x++)
90
+			{
91
+				$tempchr = ord(substr($password, $x, 1));
92
+				if ($x > 19)  $result += $charmult[$tempchr];
93
+				else if ($x > 7)  $result += $charmult[$tempchr] * 1.5;
94
+				else if ($x > 0)  $result += $charmult[$tempchr] * 2;
95
+				else  $result += 4;
96
+
97
+				$charmult[$tempchr] *= 0.75;
98
+			}
99
+
100
+			return $result;
101
+		}
102
+		else
103
+		{
104
+			if ($y > 20)  return 4 + (7 * 2) + (12 * 1.5) + $y - 20;
105
+			if ($y > 8)  return 4 + (7 * 2) + (($y - 8) * 1.5);
106
+			if ($y > 1)  return 4 + (($y - 1) * 2);
107
+
108
+			return ($y == 1 ? 4 : 0);
109
+		}
110
+	}
111
+
112
+	//--------------------------------------------------------------------
113
+
114
+	/**
115
+	 * Determines whether a password is strong enough to use. You should check
116
+	 * the password against this method and reject it if the password is not
117
+	 * strong enough.
118
+	 *
119
+	 * The following guidelines come from the author's tests against 10.4 million actual passwords
120
+	 * ( see post: http://cubicspot.blogspot.com/2012/01/how-to-calculate-password-strength-part.html )
121
+	 * and represents the suggested minimum entropy bits for different types of sites:
122
+	 *
123
+	 *      - 18 bits of entropy = minimum for ANY website.
124
+	 *      - 25 bits of entropy = minimum for a general purpose web service used relatively widely (e.g. Hotmail).
125
+	 *      - 30 bits of entropy = minimum for a web service with business critical applications (e.g. SAAS).
126
+	 *      - 40 bits of entropy = minimum for a bank or other financial service.
127
+	 *
128
+	 * The algorithm is based upon a modified version of the NIST rules which suggest the following:
129
+	 *
130
+	 *      - The first byte counts as 4 bits.
131
+	 *      - The next 7 bytes count as 2 bits each.
132
+	 *      - The next 12 bytes count as 1.5 bits each.
133
+	 *      - Anything beyond that counts as 1 bit each.
134
+	 *      - Mixed case + non-alphanumeric = up to 6 extra bits.
135
+	 *
136
+	 * @param string    $password   - The password to check
137
+	 * @param int       $minbits    - Minimum "entropy bits" that is allowed
138
+	 * @param bool      $usedict    - Should we check the password against a 300,000 word English dictionary?
139
+	 * @param int       $minwordlen -
140
+	 * @return bool
141
+	 */
142
+	public static function isStrongPassword($password, $minbits = 18, $usedict = false, $minwordlen = 4)
143
+	{
144
+		// NIST password strength rules allow up to 6 extra bits for mixed case and non-alphabetic.
145
+		$upper = false;
146
+		$lower = false;
147
+		$numeric = false;
148
+		$other = false;
149
+		$space = false;
150
+		$y = strlen($password);
151
+		for ($x = 0; $x < $y; $x++)
152
+		{
153
+			$tempchr = ord(substr($password, $x, 1));
154
+			if ($tempchr >= ord("A") && $tempchr <= ord("Z"))  $upper = true;
155
+			else if ($tempchr >= ord("a") && $tempchr <= ord("z"))  $lower = true;
156
+			else if ($tempchr >= ord("0") && $tempchr <= ord("9"))  $numeric = true;
157
+			else if ($tempchr == ord(" "))  $space = true;
158
+			else  $other = true;
159
+		}
160
+		$extrabits = ($upper && $lower && $other ? ($numeric ? 6 : 5) : ($numeric && !$upper && !$lower ? ($other ? -2 : -6) : 0));
161
+		if (!$space)  $extrabits -= 2;
162
+		else if (count(explode(" ", preg_replace('/\s+/', " ", $password))) > 3)  $extrabits++;
163
+		$result = self::getNISTNumBits($password, true) + $extrabits;
164
+
165
+		$password = strtolower($password);
166
+		$revpassword = strrev($password);
167
+		$numbits = self::getNISTNumBits($password) + $extrabits;
168
+		if ($result > $numbits)  $result = $numbits;
169
+
170
+		// Remove QWERTY strings.
171
+		$qwertystrs = array(
172
+			"1234567890-qwertyuiopasdfghjkl;zxcvbnm,./",
173
+			"1qaz2wsx3edc4rfv5tgb6yhn7ujm8ik,9ol.0p;/-['=]:?_{\"+}",
174
+			"1qaz2wsx3edc4rfv5tgb6yhn7ujm8ik9ol0p",
175
+			"qazwsxedcrfvtgbyhnujmik,ol.p;/-['=]:?_{\"+}",
176
+			"qazwsxedcrfvtgbyhnujmikolp",
177
+			"]\"/=[;.-pl,0okm9ijn8uhb7ygv6tfc5rdx4esz3wa2q1",
178
+			"pl0okm9ijn8uhb7ygv6tfc5rdx4esz3wa2q1",
179
+			"]\"/[;.pl,okmijnuhbygvtfcrdxeszwaq",
180
+			"plokmijnuhbygvtfcrdxeszwaq",
181
+			"014725836914702583697894561230258/369*+-*/",
182
+			"abcdefghijklmnopqrstuvwxyz"
183
+		);
184
+		foreach ($qwertystrs as $qwertystr)
185
+		{
186
+			$qpassword = $password;
187
+			$qrevpassword = $revpassword;
188
+			$z = 6;
189
+			do
190
+			{
191
+				$y = strlen($qwertystr) - $z;
192
+				for ($x = 0; $x < $y; $x++)
193
+				{
194
+					$str = substr($qwertystr, $x, $z);
195
+					$qpassword = str_replace($str, "*", $qpassword);
196
+					$qrevpassword = str_replace($str, "*", $qrevpassword);
197
+				}
198
+
199
+				$z--;
200
+			} while ($z > 2);
201
+
202
+			$numbits = self::getNISTNumBits($qpassword) + $extrabits;
203
+			if ($result > $numbits)  $result = $numbits;
204
+			$numbits = self::getNISTNumBits($qrevpassword) + $extrabits;
205
+			if ($result > $numbits)  $result = $numbits;
206
+
207
+			if ($result < $minbits)  return false;
208
+		}
209
+
210
+		if ($usedict && $result >= $minbits)
211
+		{
212
+			$passwords = array();
213
+
214
+			// Add keyboard shifting password variants.
215
+			$keyboardmap_down_noshift = array(
216
+				"z" => "", "x" => "", "c" => "", "v" => "", "b" => "", "n" => "", "m" => "", "," => "", "." => "", "/" => "", "<" => "", ">" => "", "?" => ""
217
+			);
218
+			if ($password == str_replace(array_keys($keyboardmap_down_noshift), array_values($keyboardmap_down_noshift), $password))
219
+			{
220
+				$keyboardmap_downright = array(
221
+					"a" => "z",
222
+					"q" => "a",
223
+					"1" => "q",
224
+					"s" => "x",
225
+					"w" => "s",
226
+					"2" => "w",
227
+					"d" => "c",
228
+					"e" => "d",
229
+					"3" => "e",
230
+					"f" => "v",
231
+					"r" => "f",
232
+					"4" => "r",
233
+					"g" => "b",
234
+					"t" => "g",
235
+					"5" => "t",
236
+					"h" => "n",
237
+					"y" => "h",
238
+					"6" => "y",
239
+					"j" => "m",
240
+					"u" => "j",
241
+					"7" => "u",
242
+					"i" => "k",
243
+					"8" => "i",
244
+					"o" => "l",
245
+					"9" => "o",
246
+					"0" => "p",
247
+				);
248
+
249
+				$keyboardmap_downleft = array(
250
+					"2" => "q",
251
+					"w" => "a",
252
+					"3" => "w",
253
+					"s" => "z",
254
+					"e" => "s",
255
+					"4" => "e",
256
+					"d" => "x",
257
+					"r" => "d",
258
+					"5" => "r",
259
+					"f" => "c",
260
+					"t" => "f",
261
+					"6" => "t",
262
+					"g" => "v",
263
+					"y" => "g",
264
+					"7" => "y",
265
+					"h" => "b",
266
+					"u" => "h",
267
+					"8" => "u",
268
+					"j" => "n",
269
+					"i" => "j",
270
+					"9" => "i",
271
+					"k" => "m",
272
+					"o" => "k",
273
+					"0" => "o",
274
+					"p" => "l",
275
+					"-" => "p",
276
+				);
277
+
278
+				$password2 = str_replace(array_keys($keyboardmap_downright), array_values($keyboardmap_downright), $password);
279
+				$passwords[] = $password2;
280
+				$passwords[] = strrev($password2);
281
+
282
+				$password2 = str_replace(array_keys($keyboardmap_downleft), array_values($keyboardmap_downleft), $password);
283
+				$passwords[] = $password2;
284
+				$passwords[] = strrev($password2);
285
+			}
286
+
287
+			// Deal with LEET-Speak substitutions.
288
+			$leetspeakmap = array(
289
+				"@" => "a",
290
+				"!" => "i",
291
+				"$" => "s",
292
+				"1" => "i",
293
+				"2" => "z",
294
+				"3" => "e",
295
+				"4" => "a",
296
+				"5" => "s",
297
+				"6" => "g",
298
+				"7" => "t",
299
+				"8" => "b",
300
+				"9" => "g",
301
+				"0" => "o"
302
+			);
303
+
304
+			$password2 = str_replace(array_keys($leetspeakmap), array_values($leetspeakmap), $password);
305
+			$passwords[] = $password2;
306
+			$passwords[] = strrev($password2);
307
+
308
+			$leetspeakmap["1"] = "l";
309
+			$password3 = str_replace(array_keys($leetspeakmap), array_values($leetspeakmap), $password);
310
+			if ($password3 != $password2)
311
+			{
312
+				$passwords[] = $password3;
313
+				$passwords[] = strrev($password3);
314
+			}
315
+
316
+			// Process the password, while looking for words in the dictionary.
317
+			$a = ord("a");
318
+			$z = ord("z");
319
+			$data = file_get_contents(DICTIONARY_PATH);
320
+			foreach ($passwords as $num => $password)
321
+			{
322
+				$y = strlen($password);
323
+				for ($x = 0; $x < $y; $x++)
324
+				{
325
+					$tempchr = ord(substr($password, $x, 1));
326
+					if ($tempchr >= $a && $tempchr <= $z)
327
+					{
328
+						for ($x2 = $x + 1; $x2 < $y; $x2++)
329
+						{
330
+							$tempchr = ord(substr($password, $x2, 1));
331
+							if ($tempchr < $a || $tempchr > $z)  break;
332
+						}
333
+
334
+						$found = false;
335
+						while (!$found && $x2 - $x >= $minwordlen)
336
+						{
337
+							$word = "/\\n" . substr($password, $x, $minwordlen);
338
+							for ($x3 = $x + $minwordlen; $x3 < $x2; $x3++)  $word .= "(" . $password{$x3};
339
+							for ($x3 = $x + $minwordlen; $x3 < $x2; $x3++)  $word .= ")?";
340
+							$word .= "\\n/";
341
+
342
+							preg_match_all($word, $data, $matches);
343
+							if (!count($matches[0]))
344
+							{
345
+								$password{$x} = "*";
346
+								$x++;
347
+								$numbits = self::getNISTNumBits(substr($password, 0, $x)) + $extrabits;
348
+								if ($numbits >= $minbits)  $found = true;
349
+							}
350
+							else
351
+							{
352
+								foreach ($matches[0] as $match)
353
+								{
354
+									$password2 = str_replace(trim($match), "*", $password);
355
+									$numbits = self::getNISTNumBits($password2) + $extrabits;
356
+									if ($result > $numbits)  $result = $numbits;
357
+
358
+									if ($result < $minbits)  return false;
359
+								}
360
+
361
+								$found = true;
362
+							}
363
+						}
364
+
365
+						if ($found)  break;
366
+
367
+						$x = $x2 - 1;
368
+					}
369
+				}
370
+			}
371
+		}
372
+
373
+		return $result >= $minbits;
374
+	}
375 375
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
  * @since       Version 1.0
31 31
  */
32 32
 
33
-define('DICTIONARY_PATH', dirname(__FILE__) .'/dictionary.txt');
33
+define('DICTIONARY_PATH', dirname(__FILE__).'/dictionary.txt');
34 34
 
35 35
 /**
36 36
  * Class Password
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      */
61 61
     public static function hashPassword($password)
62 62
     {
63
-        if (! config_item('auth.hash_cost'))
63
+        if ( ! config_item('auth.hash_cost'))
64 64
         {
65 65
             get_instance()->load->config('auth');
66 66
         }
@@ -157,8 +157,8 @@  discard block
 block discarded – undo
157 157
             else if ($tempchr == ord(" "))  $space = true;
158 158
             else  $other = true;
159 159
         }
160
-        $extrabits = ($upper && $lower && $other ? ($numeric ? 6 : 5) : ($numeric && !$upper && !$lower ? ($other ? -2 : -6) : 0));
161
-        if (!$space)  $extrabits -= 2;
160
+        $extrabits = ($upper && $lower && $other ? ($numeric ? 6 : 5) : ($numeric && ! $upper && ! $lower ? ($other ? -2 : -6) : 0));
161
+        if ( ! $space)  $extrabits -= 2;
162 162
         else if (count(explode(" ", preg_replace('/\s+/', " ", $password))) > 3)  $extrabits++;
163 163
         $result = self::getNISTNumBits($password, true) + $extrabits;
164 164
 
@@ -332,15 +332,15 @@  discard block
 block discarded – undo
332 332
                         }
333 333
 
334 334
                         $found = false;
335
-                        while (!$found && $x2 - $x >= $minwordlen)
335
+                        while ( ! $found && $x2 - $x >= $minwordlen)
336 336
                         {
337
-                            $word = "/\\n" . substr($password, $x, $minwordlen);
338
-                            for ($x3 = $x + $minwordlen; $x3 < $x2; $x3++)  $word .= "(" . $password{$x3};
337
+                            $word = "/\\n".substr($password, $x, $minwordlen);
338
+                            for ($x3 = $x + $minwordlen; $x3 < $x2; $x3++)  $word .= "(".$password{$x3};
339 339
                             for ($x3 = $x + $minwordlen; $x3 < $x2; $x3++)  $word .= ")?";
340 340
                             $word .= "\\n/";
341 341
 
342 342
                             preg_match_all($word, $data, $matches);
343
-                            if (!count($matches[0]))
343
+                            if ( ! count($matches[0]))
344 344
                             {
345 345
                                 $password{$x} = "*";
346 346
                                 $x++;
Please login to merge, or discard this patch.
Braces   +69 added lines, -29 removed lines patch added patch discarded remove patch
@@ -89,21 +89,31 @@  discard block
 block discarded – undo
89 89
             for ($x = 0; $x < $y; $x++)
90 90
             {
91 91
                 $tempchr = ord(substr($password, $x, 1));
92
-                if ($x > 19)  $result += $charmult[$tempchr];
93
-                else if ($x > 7)  $result += $charmult[$tempchr] * 1.5;
94
-                else if ($x > 0)  $result += $charmult[$tempchr] * 2;
95
-                else  $result += 4;
92
+                if ($x > 19) {
93
+                	$result += $charmult[$tempchr];
94
+                } else if ($x > 7) {
95
+                	$result += $charmult[$tempchr] * 1.5;
96
+                } else if ($x > 0) {
97
+                	$result += $charmult[$tempchr] * 2;
98
+                } else {
99
+                	$result += 4;
100
+                }
96 101
 
97 102
                 $charmult[$tempchr] *= 0.75;
98 103
             }
99 104
 
100 105
             return $result;
101
-        }
102
-        else
106
+        } else
103 107
         {
104
-            if ($y > 20)  return 4 + (7 * 2) + (12 * 1.5) + $y - 20;
105
-            if ($y > 8)  return 4 + (7 * 2) + (($y - 8) * 1.5);
106
-            if ($y > 1)  return 4 + (($y - 1) * 2);
108
+            if ($y > 20) {
109
+            	return 4 + (7 * 2) + (12 * 1.5) + $y - 20;
110
+            }
111
+            if ($y > 8) {
112
+            	return 4 + (7 * 2) + (($y - 8) * 1.5);
113
+            }
114
+            if ($y > 1) {
115
+            	return 4 + (($y - 1) * 2);
116
+            }
107 117
 
108 118
             return ($y == 1 ? 4 : 0);
109 119
         }
@@ -151,21 +161,32 @@  discard block
 block discarded – undo
151 161
         for ($x = 0; $x < $y; $x++)
152 162
         {
153 163
             $tempchr = ord(substr($password, $x, 1));
154
-            if ($tempchr >= ord("A") && $tempchr <= ord("Z"))  $upper = true;
155
-            else if ($tempchr >= ord("a") && $tempchr <= ord("z"))  $lower = true;
156
-            else if ($tempchr >= ord("0") && $tempchr <= ord("9"))  $numeric = true;
157
-            else if ($tempchr == ord(" "))  $space = true;
158
-            else  $other = true;
164
+            if ($tempchr >= ord("A") && $tempchr <= ord("Z")) {
165
+            	$upper = true;
166
+            } else if ($tempchr >= ord("a") && $tempchr <= ord("z")) {
167
+            	$lower = true;
168
+            } else if ($tempchr >= ord("0") && $tempchr <= ord("9")) {
169
+            	$numeric = true;
170
+            } else if ($tempchr == ord(" ")) {
171
+            	$space = true;
172
+            } else {
173
+            	$other = true;
174
+            }
159 175
         }
160 176
         $extrabits = ($upper && $lower && $other ? ($numeric ? 6 : 5) : ($numeric && !$upper && !$lower ? ($other ? -2 : -6) : 0));
161
-        if (!$space)  $extrabits -= 2;
162
-        else if (count(explode(" ", preg_replace('/\s+/', " ", $password))) > 3)  $extrabits++;
177
+        if (!$space) {
178
+        	$extrabits -= 2;
179
+        } else if (count(explode(" ", preg_replace('/\s+/', " ", $password))) > 3) {
180
+        	$extrabits++;
181
+        }
163 182
         $result = self::getNISTNumBits($password, true) + $extrabits;
164 183
 
165 184
         $password = strtolower($password);
166 185
         $revpassword = strrev($password);
167 186
         $numbits = self::getNISTNumBits($password) + $extrabits;
168
-        if ($result > $numbits)  $result = $numbits;
187
+        if ($result > $numbits) {
188
+        	$result = $numbits;
189
+        }
169 190
 
170 191
         // Remove QWERTY strings.
171 192
         $qwertystrs = array(
@@ -200,11 +221,17 @@  discard block
 block discarded – undo
200 221
             } while ($z > 2);
201 222
 
202 223
             $numbits = self::getNISTNumBits($qpassword) + $extrabits;
203
-            if ($result > $numbits)  $result = $numbits;
224
+            if ($result > $numbits) {
225
+            	$result = $numbits;
226
+            }
204 227
             $numbits = self::getNISTNumBits($qrevpassword) + $extrabits;
205
-            if ($result > $numbits)  $result = $numbits;
228
+            if ($result > $numbits) {
229
+            	$result = $numbits;
230
+            }
206 231
 
207
-            if ($result < $minbits)  return false;
232
+            if ($result < $minbits) {
233
+            	return false;
234
+            }
208 235
         }
209 236
 
210 237
         if ($usedict && $result >= $minbits)
@@ -328,15 +355,21 @@  discard block
 block discarded – undo
328 355
                         for ($x2 = $x + 1; $x2 < $y; $x2++)
329 356
                         {
330 357
                             $tempchr = ord(substr($password, $x2, 1));
331
-                            if ($tempchr < $a || $tempchr > $z)  break;
358
+                            if ($tempchr < $a || $tempchr > $z) {
359
+                            	break;
360
+                            }
332 361
                         }
333 362
 
334 363
                         $found = false;
335 364
                         while (!$found && $x2 - $x >= $minwordlen)
336 365
                         {
337 366
                             $word = "/\\n" . substr($password, $x, $minwordlen);
338
-                            for ($x3 = $x + $minwordlen; $x3 < $x2; $x3++)  $word .= "(" . $password{$x3};
339
-                            for ($x3 = $x + $minwordlen; $x3 < $x2; $x3++)  $word .= ")?";
367
+                            for ($x3 = $x + $minwordlen; $x3 < $x2; $x3++) {
368
+                            	$word .= "(" . $password{$x3};
369
+                            }
370
+                            for ($x3 = $x + $minwordlen; $x3 < $x2; $x3++) {
371
+                            	$word .= ")?";
372
+                            }
340 373
                             $word .= "\\n/";
341 374
 
342 375
                             preg_match_all($word, $data, $matches);
@@ -345,24 +378,31 @@  discard block
 block discarded – undo
345 378
                                 $password{$x} = "*";
346 379
                                 $x++;
347 380
                                 $numbits = self::getNISTNumBits(substr($password, 0, $x)) + $extrabits;
348
-                                if ($numbits >= $minbits)  $found = true;
349
-                            }
350
-                            else
381
+                                if ($numbits >= $minbits) {
382
+                                	$found = true;
383
+                                }
384
+                            } else
351 385
                             {
352 386
                                 foreach ($matches[0] as $match)
353 387
                                 {
354 388
                                     $password2 = str_replace(trim($match), "*", $password);
355 389
                                     $numbits = self::getNISTNumBits($password2) + $extrabits;
356
-                                    if ($result > $numbits)  $result = $numbits;
390
+                                    if ($result > $numbits) {
391
+                                    	$result = $numbits;
392
+                                    }
357 393
 
358
-                                    if ($result < $minbits)  return false;
394
+                                    if ($result < $minbits) {
395
+                                    	return false;
396
+                                    }
359 397
                                 }
360 398
 
361 399
                                 $found = true;
362 400
                             }
363 401
                         }
364 402
 
365
-                        if ($found)  break;
403
+                        if ($found) {
404
+                        	break;
405
+                        }
366 406
 
367 407
                         $x = $x2 - 1;
368 408
                     }
Please login to merge, or discard this patch.
myth/CIModules/auth/controllers/Auth.php 3 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -71,14 +71,14 @@  discard block
 block discarded – undo
71 71
                 'password' => $this->input->post('password')
72 72
             ];
73 73
 
74
-            $remember = (bool)$this->input->post('remember');
74
+            $remember = (bool) $this->input->post('remember');
75 75
 
76 76
             if ($auth->login($post_data, $remember))
77 77
             {
78 78
 	            // Is the user being forced to reset their password?
79 79
 	            if ($auth->user()['force_pass_reset'] == 1)
80 80
 	            {
81
-		            redirect( Route::named('change_pass') );
81
+		            redirect(Route::named('change_pass'));
82 82
 	            }
83 83
 
84 84
                 unset($_SESSION['redirect_url']);
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
             if ($auth->registerUser($post_data))
136 136
             {
137 137
                 $this->setMessage(lang('auth.did_register'), 'success');
138
-                redirect( Route::named('login') );
138
+                redirect(Route::named('login'));
139 139
             }
140 140
             else
141 141
             {
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
             if ($auth->activateUser($post_data))
169 169
             {
170 170
                 $this->setMessage(lang('auth.did_activate'), 'success');
171
-                redirect( Route::named('login') );
171
+                redirect(Route::named('login'));
172 172
             }
173 173
             else
174 174
             {
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
             if ($auth->remindUser($this->input->post('email')))
202 202
             {
203 203
                 $this->setMessage(lang('auth.send_success'), 'success');
204
-                redirect( Route::named('reset_pass') );
204
+                redirect(Route::named('reset_pass'));
205 205
             }
206 206
             else
207 207
             {
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
             if ($auth->resetPassword($credentials, $password, $pass_confirm))
237 237
             {
238 238
                 $this->setMessage(lang('auth.new_password_success'), 'success');
239
-                redirect( Route::named('login') );
239
+                redirect(Route::named('login'));
240 240
             }
241 241
             else
242 242
             {
@@ -267,9 +267,9 @@  discard block
 block discarded – undo
267 267
 		$this->load->model('user_model');
268 268
 		$auth->useModel($this->user_model);
269 269
 
270
-		if (! $auth->isLoggedIn())
270
+		if ( ! $auth->isLoggedIn())
271 271
 		{
272
-			redirect( Route::named('login') );
272
+			redirect(Route::named('login'));
273 273
 		}
274 274
 
275 275
 		$this->load->helper('form');
@@ -281,35 +281,35 @@  discard block
 block discarded – undo
281 281
 			$pass_confirm = $this->input->post('pass_confirm');
282 282
 
283 283
 			// Does the current password match?
284
-			if (! password_verify($current_pass, $auth->user()['password_hash']))
284
+			if ( ! password_verify($current_pass, $auth->user()['password_hash']))
285 285
 			{
286
-				$this->setMessage( lang('auth.bad_current_pass'), 'warning');
287
-				redirect( current_url() );
286
+				$this->setMessage(lang('auth.bad_current_pass'), 'warning');
287
+				redirect(current_url());
288 288
 			}
289 289
 
290 290
 			// Do the passwords match?
291 291
 			if ($password != $pass_confirm)
292 292
 			{
293
-				$this->setMessage( lang('auth.pass_must_match'), 'warning');
294
-				redirect( current_url() );
293
+				$this->setMessage(lang('auth.pass_must_match'), 'warning');
294
+				redirect(current_url());
295 295
 			}
296 296
 
297 297
 			$hash = \Myth\Auth\Password::hashPassword($password);
298 298
 
299
-			if (! $this->user_model->update( $auth->id(), ['password_hash' => $hash, 'force_pass_reset' => 0]) )
299
+			if ( ! $this->user_model->update($auth->id(), ['password_hash' => $hash, 'force_pass_reset' => 0]))
300 300
 			{
301
-				$this->setMessage( 'Error: '. $this->user_model->error(), 'danger');
302
-				redirect( current_url() );
301
+				$this->setMessage('Error: '.$this->user_model->error(), 'danger');
302
+				redirect(current_url());
303 303
 			}
304 304
 
305 305
 			$redirect_url = $this->session->userdata('redirect_url');
306 306
 			unset($_SESSION['redirect_url']);
307 307
 
308
-			$this->setMessage( lang('auth.new_password_success'), 'success' );
308
+			$this->setMessage(lang('auth.new_password_success'), 'success');
309 309
 
310 310
 			$auth->logout();
311 311
 
312
-			redirect( Route::named('login') );
312
+			redirect(Route::named('login'));
313 313
 		}
314 314
 
315 315
 		$this->addScript('register.js');
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -136,8 +136,7 @@  discard block
 block discarded – undo
136 136
             {
137 137
                 $this->setMessage(lang('auth.did_register'), 'success');
138 138
                 redirect( Route::named('login') );
139
-            }
140
-            else
139
+            } else
141 140
             {
142 141
                 $this->setMessage($auth->error(), 'danger');
143 142
             }
@@ -169,8 +168,7 @@  discard block
 block discarded – undo
169 168
             {
170 169
                 $this->setMessage(lang('auth.did_activate'), 'success');
171 170
                 redirect( Route::named('login') );
172
-            }
173
-            else
171
+            } else
174 172
             {
175 173
                 $this->setMessage($auth->error(), 'danger');
176 174
             }
@@ -202,8 +200,7 @@  discard block
 block discarded – undo
202 200
             {
203 201
                 $this->setMessage(lang('auth.send_success'), 'success');
204 202
                 redirect( Route::named('reset_pass') );
205
-            }
206
-            else
203
+            } else
207 204
             {
208 205
                 $this->setMessage($auth->error(), 'danger');
209 206
             }
@@ -237,8 +234,7 @@  discard block
 block discarded – undo
237 234
             {
238 235
                 $this->setMessage(lang('auth.new_password_success'), 'success');
239 236
                 redirect( Route::named('login') );
240
-            }
241
-            else
237
+            } else
242 238
             {
243 239
                 $this->setMessage($auth->error(), 'danger');
244 240
             }
Please login to merge, or discard this patch.
Indentation   +234 added lines, -234 removed lines patch added patch discarded remove patch
@@ -36,225 +36,225 @@  discard block
 block discarded – undo
36 36
 class Auth extends \Myth\Controllers\ThemedController
37 37
 {
38 38
 
39
-    public function __construct()
40
-    {
41
-        parent::__construct();
42
-
43
-        $this->config->load('auth');
44
-        $this->lang->load('auth');
45
-        $this->load->library('session');
46
-    }
47
-
48
-    //--------------------------------------------------------------------
49
-
50
-    public function login()
51
-    {
52
-        $this->load->helper('form');
53
-
54
-        $auth = new LocalAuthentication();
55
-        $this->load->model('user_model');
56
-        $auth->useModel($this->user_model);
57
-
58
-        $redirect_url = $this->session->userdata('redirect_url');
59
-
60
-        // No need to login again if they are already logged in...
61
-        if ($auth->isLoggedIn())
62
-        {
63
-            unset($_SESSION['redirect_url']);
64
-            redirect($redirect_url);
65
-        }
66
-
67
-        if ($this->input->post())
68
-        {
69
-            $post_data = [
70
-                'email'    => $this->input->post('email'),
71
-                'password' => $this->input->post('password')
72
-            ];
73
-
74
-            $remember = (bool)$this->input->post('remember');
75
-
76
-            if ($auth->login($post_data, $remember))
77
-            {
78
-	            // Is the user being forced to reset their password?
79
-	            if ($auth->user()['force_pass_reset'] == 1)
80
-	            {
81
-		            redirect( Route::named('change_pass') );
82
-	            }
83
-
84
-                unset($_SESSION['redirect_url']);
85
-                $this->setMessage(lang('auth.did_login'), 'success');
86
-                redirect($redirect_url);
87
-            }
88
-
89
-            $this->setMessage(lang('auth.invalid_user'), 'danger');
90
-        }
91
-
92
-        $this->themer->setLayout('login');
93
-        $this->render();
94
-    }
95
-
96
-    //--------------------------------------------------------------------
97
-
98
-    public function logout()
99
-    {
100
-        $auth = new LocalAuthentication();
101
-        $this->load->model('user_model');
102
-        $auth->useModel($this->user_model);
103
-
104
-        if ($auth->isLoggedIn())
105
-        {
106
-            $auth->logout();
107
-
108
-            $this->setMessage(lang('auth.did_logout'), 'success');
109
-        }
110
-
111
-        redirect('/');
112
-    }
113
-
114
-    //--------------------------------------------------------------------
115
-
116
-    public function register()
117
-    {
118
-        $this->load->helper('form');
119
-
120
-        if ($this->input->post())
121
-        {
122
-            $auth = new LocalAuthentication();
123
-            $this->load->model('user_model');
124
-            $auth->useModel($this->user_model);
125
-
126
-            $post_data = [
127
-                'first_name'   => $this->input->post('first_name'),
128
-                'last_name'    => $this->input->post('last_name'),
129
-                'email'        => $this->input->post('email'),
130
-                'username'     => $this->input->post('username'),
131
-                'password'     => $this->input->post('password'),
132
-                'pass_confirm' => $this->input->post('pass_confirm')
133
-            ];
134
-
135
-            if ($auth->registerUser($post_data))
136
-            {
137
-                $this->setMessage(lang('auth.did_register'), 'success');
138
-                redirect( Route::named('login') );
139
-            }
140
-            else
141
-            {
142
-                $this->setMessage($auth->error(), 'danger');
143
-            }
144
-        }
145
-
146
-        $this->addScript('register.js');
147
-        $this->themer->setLayout('login');
148
-        $this->render();
149
-    }
150
-
151
-    //--------------------------------------------------------------------
152
-
153
-    public function activate_user()
154
-    {
155
-        $this->load->helper('form');
156
-
157
-        if ($this->input->post())
158
-        {
159
-            $auth = new LocalAuthentication();
160
-            $this->load->model('user_model');
161
-            $auth->useModel($this->user_model);
162
-
163
-            $post_data = [
164
-                  'email' => $this->input->post('email'),
165
-                  'code'  => $this->input->post('code')
166
-            ];
167
-
168
-            if ($auth->activateUser($post_data))
169
-            {
170
-                $this->setMessage(lang('auth.did_activate'), 'success');
171
-                redirect( Route::named('login') );
172
-            }
173
-            else
174
-            {
175
-                $this->setMessage($auth->error(), 'danger');
176
-            }
177
-        }
178
-
179
-        $data = [
180
-            'email' => $this->input->get('e'),
181
-            'code'  => $this->input->get('code')
182
-        ];
183
-
184
-        $this->themer->setLayout('login');
185
-        $this->render($data);
186
-    }
187
-
188
-    //--------------------------------------------------------------------
189
-
190
-
191
-    public function forgot_password()
192
-    {
193
-        $this->load->helper('form');
194
-
195
-        if ($this->input->post())
196
-        {
197
-            $auth = new LocalAuthentication();
198
-            $this->load->model('user_model');
199
-            $auth->useModel($this->user_model);
200
-
201
-            if ($auth->remindUser($this->input->post('email')))
202
-            {
203
-                $this->setMessage(lang('auth.send_success'), 'success');
204
-                redirect( Route::named('reset_pass') );
205
-            }
206
-            else
207
-            {
208
-                $this->setMessage($auth->error(), 'danger');
209
-            }
210
-        }
211
-
212
-        $this->themer->setLayout('login');
213
-        $this->render();
214
-    }
215
-
216
-    //--------------------------------------------------------------------
217
-
218
-    public function reset_password()
219
-    {
220
-        $this->load->helper('form');
221
-
222
-        if ($this->input->post())
223
-        {
224
-            $auth = new LocalAuthentication();
225
-            $this->load->model('user_model');
226
-            $auth->useModel($this->user_model);
227
-
228
-            $credentials = [
229
-                'email' => $this->input->post('email'),
230
-                'code'  => $this->input->post('code')
231
-            ];
232
-
233
-            $password     = $this->input->post('password');
234
-            $pass_confirm = $this->input->post('pass_confirm');
235
-
236
-            if ($auth->resetPassword($credentials, $password, $pass_confirm))
237
-            {
238
-                $this->setMessage(lang('auth.new_password_success'), 'success');
239
-                redirect( Route::named('login') );
240
-            }
241
-            else
242
-            {
243
-                $this->setMessage($auth->error(), 'danger');
244
-            }
245
-        }
246
-
247
-        $data = [
248
-            'email' => $this->input->get('e'),
249
-            'code'  => $this->input->get('code')
250
-        ];
251
-
252
-        $this->addScript('register.js');
253
-        $this->themer->setLayout('login');
254
-        $this->render($data);
255
-    }
256
-
257
-    //--------------------------------------------------------------------
39
+	public function __construct()
40
+	{
41
+		parent::__construct();
42
+
43
+		$this->config->load('auth');
44
+		$this->lang->load('auth');
45
+		$this->load->library('session');
46
+	}
47
+
48
+	//--------------------------------------------------------------------
49
+
50
+	public function login()
51
+	{
52
+		$this->load->helper('form');
53
+
54
+		$auth = new LocalAuthentication();
55
+		$this->load->model('user_model');
56
+		$auth->useModel($this->user_model);
57
+
58
+		$redirect_url = $this->session->userdata('redirect_url');
59
+
60
+		// No need to login again if they are already logged in...
61
+		if ($auth->isLoggedIn())
62
+		{
63
+			unset($_SESSION['redirect_url']);
64
+			redirect($redirect_url);
65
+		}
66
+
67
+		if ($this->input->post())
68
+		{
69
+			$post_data = [
70
+				'email'    => $this->input->post('email'),
71
+				'password' => $this->input->post('password')
72
+			];
73
+
74
+			$remember = (bool)$this->input->post('remember');
75
+
76
+			if ($auth->login($post_data, $remember))
77
+			{
78
+				// Is the user being forced to reset their password?
79
+				if ($auth->user()['force_pass_reset'] == 1)
80
+				{
81
+					redirect( Route::named('change_pass') );
82
+				}
83
+
84
+				unset($_SESSION['redirect_url']);
85
+				$this->setMessage(lang('auth.did_login'), 'success');
86
+				redirect($redirect_url);
87
+			}
88
+
89
+			$this->setMessage(lang('auth.invalid_user'), 'danger');
90
+		}
91
+
92
+		$this->themer->setLayout('login');
93
+		$this->render();
94
+	}
95
+
96
+	//--------------------------------------------------------------------
97
+
98
+	public function logout()
99
+	{
100
+		$auth = new LocalAuthentication();
101
+		$this->load->model('user_model');
102
+		$auth->useModel($this->user_model);
103
+
104
+		if ($auth->isLoggedIn())
105
+		{
106
+			$auth->logout();
107
+
108
+			$this->setMessage(lang('auth.did_logout'), 'success');
109
+		}
110
+
111
+		redirect('/');
112
+	}
113
+
114
+	//--------------------------------------------------------------------
115
+
116
+	public function register()
117
+	{
118
+		$this->load->helper('form');
119
+
120
+		if ($this->input->post())
121
+		{
122
+			$auth = new LocalAuthentication();
123
+			$this->load->model('user_model');
124
+			$auth->useModel($this->user_model);
125
+
126
+			$post_data = [
127
+				'first_name'   => $this->input->post('first_name'),
128
+				'last_name'    => $this->input->post('last_name'),
129
+				'email'        => $this->input->post('email'),
130
+				'username'     => $this->input->post('username'),
131
+				'password'     => $this->input->post('password'),
132
+				'pass_confirm' => $this->input->post('pass_confirm')
133
+			];
134
+
135
+			if ($auth->registerUser($post_data))
136
+			{
137
+				$this->setMessage(lang('auth.did_register'), 'success');
138
+				redirect( Route::named('login') );
139
+			}
140
+			else
141
+			{
142
+				$this->setMessage($auth->error(), 'danger');
143
+			}
144
+		}
145
+
146
+		$this->addScript('register.js');
147
+		$this->themer->setLayout('login');
148
+		$this->render();
149
+	}
150
+
151
+	//--------------------------------------------------------------------
152
+
153
+	public function activate_user()
154
+	{
155
+		$this->load->helper('form');
156
+
157
+		if ($this->input->post())
158
+		{
159
+			$auth = new LocalAuthentication();
160
+			$this->load->model('user_model');
161
+			$auth->useModel($this->user_model);
162
+
163
+			$post_data = [
164
+				  'email' => $this->input->post('email'),
165
+				  'code'  => $this->input->post('code')
166
+			];
167
+
168
+			if ($auth->activateUser($post_data))
169
+			{
170
+				$this->setMessage(lang('auth.did_activate'), 'success');
171
+				redirect( Route::named('login') );
172
+			}
173
+			else
174
+			{
175
+				$this->setMessage($auth->error(), 'danger');
176
+			}
177
+		}
178
+
179
+		$data = [
180
+			'email' => $this->input->get('e'),
181
+			'code'  => $this->input->get('code')
182
+		];
183
+
184
+		$this->themer->setLayout('login');
185
+		$this->render($data);
186
+	}
187
+
188
+	//--------------------------------------------------------------------
189
+
190
+
191
+	public function forgot_password()
192
+	{
193
+		$this->load->helper('form');
194
+
195
+		if ($this->input->post())
196
+		{
197
+			$auth = new LocalAuthentication();
198
+			$this->load->model('user_model');
199
+			$auth->useModel($this->user_model);
200
+
201
+			if ($auth->remindUser($this->input->post('email')))
202
+			{
203
+				$this->setMessage(lang('auth.send_success'), 'success');
204
+				redirect( Route::named('reset_pass') );
205
+			}
206
+			else
207
+			{
208
+				$this->setMessage($auth->error(), 'danger');
209
+			}
210
+		}
211
+
212
+		$this->themer->setLayout('login');
213
+		$this->render();
214
+	}
215
+
216
+	//--------------------------------------------------------------------
217
+
218
+	public function reset_password()
219
+	{
220
+		$this->load->helper('form');
221
+
222
+		if ($this->input->post())
223
+		{
224
+			$auth = new LocalAuthentication();
225
+			$this->load->model('user_model');
226
+			$auth->useModel($this->user_model);
227
+
228
+			$credentials = [
229
+				'email' => $this->input->post('email'),
230
+				'code'  => $this->input->post('code')
231
+			];
232
+
233
+			$password     = $this->input->post('password');
234
+			$pass_confirm = $this->input->post('pass_confirm');
235
+
236
+			if ($auth->resetPassword($credentials, $password, $pass_confirm))
237
+			{
238
+				$this->setMessage(lang('auth.new_password_success'), 'success');
239
+				redirect( Route::named('login') );
240
+			}
241
+			else
242
+			{
243
+				$this->setMessage($auth->error(), 'danger');
244
+			}
245
+		}
246
+
247
+		$data = [
248
+			'email' => $this->input->get('e'),
249
+			'code'  => $this->input->get('code')
250
+		];
251
+
252
+		$this->addScript('register.js');
253
+		$this->themer->setLayout('login');
254
+		$this->render($data);
255
+	}
256
+
257
+	//--------------------------------------------------------------------
258 258
 
259 259
 	/**
260 260
 	 * Allows a logged in user to enter their current password
@@ -320,24 +320,24 @@  discard block
 block discarded – undo
320 320
 	//--------------------------------------------------------------------
321 321
 
322 322
 
323
-    //--------------------------------------------------------------------
324
-    // AJAX Methods
325
-    //--------------------------------------------------------------------
323
+	//--------------------------------------------------------------------
324
+	// AJAX Methods
325
+	//--------------------------------------------------------------------
326 326
 
327
-    /**
328
-     * Checks the password strength and returns pass/fail.
329
-     *
330
-     * @param $str
331
-     */
332
-    public function password_check($str)
333
-    {
334
-        $this->load->helper('auth/password');
327
+	/**
328
+	 * Checks the password strength and returns pass/fail.
329
+	 *
330
+	 * @param $str
331
+	 */
332
+	public function password_check($str)
333
+	{
334
+		$this->load->helper('auth/password');
335 335
 
336
-        $strength = isStrongPassword($str);
336
+		$strength = isStrongPassword($str);
337 337
 
338
-        $this->renderJSON(['status' => $strength ? 'pass' : 'fail']);
339
-    }
338
+		$this->renderJSON(['status' => $strength ? 'pass' : 'fail']);
339
+	}
340 340
 
341
-    //--------------------------------------------------------------------
341
+	//--------------------------------------------------------------------
342 342
 
343 343
 }
Please login to merge, or discard this patch.
myth/CIModules/auth/controllers/Test.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@
 block discarded – undo
46 46
 	public function index($target_time = 50)
47 47
 	{
48 48
 		// Convert the milliseconds to seconds.
49
-	    $target_time = $target_time / 1000;
49
+		$target_time = $target_time / 1000;
50 50
 
51 51
 		CLI::write('Testing for password hash value with a target time of '. $target_time .' seconds...');
52 52
 
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 		// Convert the milliseconds to seconds.
49 49
 	    $target_time = $target_time / 1000;
50 50
 
51
-		CLI::write('Testing for password hash value with a target time of '. $target_time .' seconds...');
51
+		CLI::write('Testing for password hash value with a target time of '.$target_time.' seconds...');
52 52
 
53 53
 		// Taken from the PHP manual
54 54
 		$cost = 8;
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 			$end = microtime(true);
60 60
 		} while (($end - $start) < $target_time);
61 61
 
62
-		CLI::write("Hash value should be set to: ". CLI::color($cost, 'green'));
62
+		CLI::write("Hash value should be set to: ".CLI::color($cost, 'green'));
63 63
 	}
64 64
 	
65 65
 	//--------------------------------------------------------------------
Please login to merge, or discard this patch.
myth/CIModules/auth/helpers/password_helper.php 2 patches
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -32,28 +32,28 @@
 block discarded – undo
32 32
 
33 33
 if (! function_exists('isStrongPassword'))
34 34
 {
35
-    /**
36
-     * Works with Myth\Auth\Password to enforce a strong password.
37
-     * Uses settings from the auth config file.
38
-     *
39
-     * @param $password
40
-     */
41
-    function isStrongPassword($password)
42
-    {
43
-        $min_strength = config_item('auth.min_password_strength');
44
-        $use_dict = config_item('auth.use_dictionary');
35
+	/**
36
+	 * Works with Myth\Auth\Password to enforce a strong password.
37
+	 * Uses settings from the auth config file.
38
+	 *
39
+	 * @param $password
40
+	 */
41
+	function isStrongPassword($password)
42
+	{
43
+		$min_strength = config_item('auth.min_password_strength');
44
+		$use_dict = config_item('auth.use_dictionary');
45 45
 
46
-        $strong = \Myth\Auth\Password::isStrongPassword($password, $min_strength, $use_dict);
46
+		$strong = \Myth\Auth\Password::isStrongPassword($password, $min_strength, $use_dict);
47 47
 
48
-        if (! $strong)
49
-        {
50
-            if (isset(get_instance()->form_validation))
51
-            {
52
-                get_instance()->form_validation->set_message('isStrongPassword', lang('auth.pass_not_strong'));
53
-            }
54
-            return false;
55
-        }
48
+		if (! $strong)
49
+		{
50
+			if (isset(get_instance()->form_validation))
51
+			{
52
+				get_instance()->form_validation->set_message('isStrongPassword', lang('auth.pass_not_strong'));
53
+			}
54
+			return false;
55
+		}
56 56
 
57
-        return true;
58
-    }
57
+		return true;
58
+	}
59 59
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
  * @since       Version 1.0
31 31
  */
32 32
 
33
-if (! function_exists('isStrongPassword'))
33
+if ( ! function_exists('isStrongPassword'))
34 34
 {
35 35
     /**
36 36
      * Works with Myth\Auth\Password to enforce a strong password.
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 
46 46
         $strong = \Myth\Auth\Password::isStrongPassword($password, $min_strength, $use_dict);
47 47
 
48
-        if (! $strong)
48
+        if ( ! $strong)
49 49
         {
50 50
             if (isset(get_instance()->form_validation))
51 51
             {
Please login to merge, or discard this patch.