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 ( 66d82f...f306bc )
by Lonnie
06:21
created
myth/Auth/LocalAuthentication.php 1 patch
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -62,21 +62,21 @@  discard block
 block discarded – undo
62 62
 
63 63
     //--------------------------------------------------------------------
64 64
 
65
-    public function __construct( $ci=null )
65
+    public function __construct($ci = null)
66 66
     {
67 67
         if ($ci)
68 68
         {
69
-            $this->ci= $ci;
69
+            $this->ci = $ci;
70 70
         }
71 71
         else
72 72
         {
73
-            $this->ci =& get_instance();
73
+            $this->ci = & get_instance();
74 74
         }
75 75
 
76 76
         // Get our compatibility password file loaded up.
77
-        if (! function_exists('password_hash'))
77
+        if ( ! function_exists('password_hash'))
78 78
         {
79
-            require_once dirname(__FILE__) .'password.php';
79
+            require_once dirname(__FILE__).'password.php';
80 80
         }
81 81
 
82 82
         if (empty($this->ci->session))
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
      * @param bool  $remember
102 102
      * @return bool|mixed
103 103
      */
104
-    public function login($credentials, $remember=false)
104
+    public function login($credentials, $remember = false)
105 105
     {
106 106
         $user = $this->validate($credentials, true);
107 107
 
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
             $email = $user ? $user['email'] : $credentials['email'];
118 118
             // If throttling time is above zero, we can't allow
119 119
         	// logins now.
120
-            $time = (int)$this->isThrottled($email);
120
+            $time = (int) $this->isThrottled($email);
121 121
             if ($time > 0)
122 122
             {
123 123
                 $this->error = sprintf(lang('auth.throttled'), $time);
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
             }
126 126
         }
127 127
 
128
-        if (! $user)
128
+        if ( ! $user)
129 129
         {
130 130
         	if (empty($this->error))
131 131
             {
@@ -160,11 +160,11 @@  discard block
 block discarded – undo
160 160
      * @param bool $return_user
161 161
      * @return mixed
162 162
      */
163
-    public function validate($credentials, $return_user=false)
163
+    public function validate($credentials, $return_user = false)
164 164
     {
165 165
         // We do not want to force case-sensitivity on things
166 166
         // like username and email for usability sake.
167
-        if (! empty($credentials['email']))
167
+        if ( ! empty($credentials['email']))
168 168
         {
169 169
             $credentials['email'] = strtolower($credentials['email']);
170 170
         }
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
         if (empty($credentials['password']) || count($credentials) < 2)
174 174
         {
175 175
         	// If an email is present, log the attempt
176
-            if (! empty($credentials['email']))
176
+            if ( ! empty($credentials['email']))
177 177
             {
178 178
                 $this->ci->login_model->recordLoginAttempt($credentials['email']);
179 179
             }
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
         {
190 190
             $this->error = lang('auth.too_many_credentials');
191 191
             // If an email is present, log the attempt
192
-            if (! empty($credentials['email']))
192
+            if ( ! empty($credentials['email']))
193 193
             {
194 194
                 $this->ci->login_model->recordLoginAttempt($credentials['email']);
195 195
             }
@@ -197,11 +197,11 @@  discard block
 block discarded – undo
197 197
         }
198 198
 
199 199
         // Ensure that the fields are allowed validation fields
200
-        if (! in_array(key($credentials), config_item('auth.valid_fields')) )
200
+        if ( ! in_array(key($credentials), config_item('auth.valid_fields')))
201 201
         {
202 202
             $this->error = lang('auth.invalid_credentials');
203 203
             // If an email is present, log the attempt
204
-            if (! empty($credentials['email']))
204
+            if ( ! empty($credentials['email']))
205 205
             {
206 206
                 $this->ci->login_model->recordLoginAttempt($credentials['email']);
207 207
             }
@@ -213,11 +213,11 @@  discard block
 block discarded – undo
213 213
                                  ->where($credentials)
214 214
                                  ->first();
215 215
 
216
-        if (! $user)
216
+        if ( ! $user)
217 217
         {
218 218
             $this->error = lang('auth.invalid_user');
219 219
             // If an email is present, log the attempt
220
-            if (! empty($credentials['email']))
220
+            if ( ! empty($credentials['email']))
221 221
             {
222 222
                 $this->ci->login_model->recordLoginAttempt($credentials['email']);
223 223
             }
@@ -225,9 +225,9 @@  discard block
 block discarded – undo
225 225
         }
226 226
 
227 227
         // Now, try matching the passwords.
228
-        $result =  password_verify($password, $user['password_hash']);
228
+        $result = password_verify($password, $user['password_hash']);
229 229
 
230
-        if (! $result)
230
+        if ( ! $result)
231 231
         {
232 232
             $this->error = lang('auth.invalid_password');
233 233
             $this->ci->login_model->recordLoginAttempt($user['email']);
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
         // This would be due to the hash algorithm or hash
239 239
         // cost changing since the last time that a user
240 240
         // logged in.
241
-        if (password_needs_rehash($user['password_hash'], PASSWORD_DEFAULT, ['cost' => config_item('auth.hash_cost')] ))
241
+        if (password_needs_rehash($user['password_hash'], PASSWORD_DEFAULT, ['cost' => config_item('auth.hash_cost')]))
242 242
         {
243 243
             $new_hash = Password::hashPassword($password);
244 244
             $this->user_model->skip_validation()
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
         }
248 248
 
249 249
         // Is the user active?
250
-        if (! $user['active'])
250
+        if ( ! $user['active'])
251 251
         {
252 252
             $this->error = lang('auth.inactive_account');
253 253
             return false;
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
     {
268 268
         $this->ci->load->helper('cookie');
269 269
 
270
-        if (! Events::trigger('beforeLogout', [$this->user]))
270
+        if ( ! Events::trigger('beforeLogout', [$this->user]))
271 271
         {
272 272
             return false;
273 273
         }
@@ -276,10 +276,10 @@  discard block
 block discarded – undo
276 276
         // available for flash messages, etc.
277 277
         if (isset($_SESSION))
278 278
         {
279
-            foreach ( $_SESSION as $key => $value )
279
+            foreach ($_SESSION as $key => $value)
280 280
             {
281
-                $_SESSION[ $key ] = NULL;
282
-                unset( $_SESSION[ $key ] );
281
+                $_SESSION[$key] = NULL;
282
+                unset($_SESSION[$key]);
283 283
             }
284 284
         }
285 285
         // Also, regenerate the session ID for a touch of added safety.
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
     {
306 306
         $id = $this->ci->session->userdata('logged_in');
307 307
 
308
-        if (! $id)
308
+        if ( ! $id)
309 309
         {
310 310
             return false;
311 311
         }
@@ -313,10 +313,10 @@  discard block
 block discarded – undo
313 313
         // If the user var hasn't been filled in, we need to fill it in,
314 314
         // since this method will typically be used as the only method
315 315
         // to determine whether a user is logged in or not.
316
-        if (! $this->user)
316
+        if ( ! $this->user)
317 317
         {
318 318
             $this->user = $this->user_model->as_array()
319
-                                           ->find_by('id', (int)$id);
319
+                                           ->find_by('id', (int) $id);
320 320
 
321 321
             if (empty($this->user))
322 322
             {
@@ -340,14 +340,14 @@  discard block
 block discarded – undo
340 340
      */
341 341
     public function viaRemember()
342 342
     {
343
-        if (! config_item('auth.allow_remembering'))
343
+        if ( ! config_item('auth.allow_remembering'))
344 344
         {
345 345
             return false;
346 346
         }
347 347
 
348 348
         $this->ci->load->helper('cookie');
349 349
 
350
-        if (! $token = get_cookie('remember'))
350
+        if ( ! $token = get_cookie('remember'))
351 351
         {
352 352
             return false;
353 353
         }
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
         $query = $this->ci->db->where('hash', $this->ci->login_model->hashRememberToken($token))
357 357
                               ->get('auth_tokens');
358 358
 
359
-        if (! $query->num_rows())
359
+        if ( ! $query->num_rows())
360 360
         {
361 361
             return false;
362 362
         }
@@ -394,16 +394,16 @@  discard block
 block discarded – undo
394 394
         // If via email, we need to generate a hash
395 395
         $this->ci->load->helper('string');
396 396
         $token = random_string('alnum', 24);
397
-        $user_data['activate_hash'] = hash('sha1', config_item('auth.salt') . $token);
397
+        $user_data['activate_hash'] = hash('sha1', config_item('auth.salt').$token);
398 398
 
399 399
         // Email should NOT be case sensitive.
400
-        if (! empty($user_data['email']))
400
+        if ( ! empty($user_data['email']))
401 401
         {
402 402
             $user_data['email'] = strtolower($user_data['email']);
403 403
         }
404 404
 
405 405
         // Save the user
406
-        if (! $id = $this->user_model->insert($user_data))
406
+        if ( ! $id = $this->user_model->insert($user_data))
407 407
         {
408 408
             $this->error = $this->user_model->error();
409 409
             return false;
@@ -434,25 +434,25 @@  discard block
 block discarded – undo
434 434
     {
435 435
         $post = [
436 436
             'email'         => $data['email'],
437
-            'activate_hash' => hash('sha1', config_item('auth.salt') . $data['code'])
437
+            'activate_hash' => hash('sha1', config_item('auth.salt').$data['code'])
438 438
         ];
439 439
 
440 440
         $user = $this->user_model->where($post)
441 441
                                  ->first();
442 442
 
443
-        if (! $user) {
443
+        if ( ! $user) {
444 444
             $this->error = $this->user_model->error() ? $this->user_model->error() : lang('auth.activate_no_user');
445 445
 
446 446
             return false;
447 447
         }
448 448
 
449
-        if (! $this->user_model->update($user->id, ['active' => 1, 'activate_hash' => null]))
449
+        if ( ! $this->user_model->update($user->id, ['active' => 1, 'activate_hash' => null]))
450 450
         {
451 451
             $this->error = $this->user_model->error();
452 452
             return false;
453 453
         }
454 454
 
455
-        Events::trigger('didActivate', [(array)$user]);
455
+        Events::trigger('didActivate', [(array) $user]);
456 456
 
457 457
         return true;
458 458
     }
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
      */
468 468
     public function activateUserById($id)
469 469
     {
470
-        if (! $this->user_model->update($id, ['active' => 1, 'activate_hash' => null]))
470
+        if ( ! $this->user_model->update($id, ['active' => 1, 'activate_hash' => null]))
471 471
         {
472 472
             $this->error = $this->user_model->error();
473 473
             return false;
@@ -499,12 +499,12 @@  discard block
 block discarded – undo
499 499
      */
500 500
     public function id()
501 501
     {
502
-        if (! is_array($this->user) || empty($this->user['id']))
502
+        if ( ! is_array($this->user) || empty($this->user['id']))
503 503
         {
504 504
             return null;
505 505
         }
506 506
 
507
-        return (int)$this->user['id'];
507
+        return (int) $this->user['id'];
508 508
     }
509 509
 
510 510
     //--------------------------------------------------------------------
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
     public function isThrottled($email)
522 522
     {
523 523
         // Not throttling? Get outta here!
524
-        if (! config_item('auth.allow_throttling'))
524
+        if ( ! config_item('auth.allow_throttling'))
525 525
         {
526 526
             return false;
527 527
         }
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
         {
586 586
             $this->error = lang('auth.bruteBan_notice');
587 587
 
588
-            $ban_time = 60 * 15;    // 15 minutes
588
+            $ban_time = 60 * 15; // 15 minutes
589 589
             $_SESSION['bruteBan'] = time() + $ban_time;
590 590
             return $ban_time;
591 591
         }
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
         // Is it a valid user?
634 634
         $user = $this->user_model->find_by('email', $email);
635 635
 
636
-        if (! $user)
636
+        if ( ! $user)
637 637
         {
638 638
             $this->error = lang('auth.invalid_email');
639 639
             return false;
@@ -642,17 +642,17 @@  discard block
 block discarded – undo
642 642
         // Generate/store our codes
643 643
         $this->ci->load->helper('string');
644 644
         $token = random_string('alnum', 24);
645
-        $hash = hash('sha1', config_item('auth.salt') .$token);
645
+        $hash = hash('sha1', config_item('auth.salt').$token);
646 646
 
647 647
         $result = $this->user_model->update($user->id, ['reset_hash' => $hash]);
648 648
 
649
-        if (! $result)
649
+        if ( ! $result)
650 650
         {
651 651
             $this->error = $this->user_model->error();
652 652
             return false;
653 653
         }
654 654
 
655
-        Events::trigger('didRemindUser', [(array)$user, $token]);
655
+        Events::trigger('didRemindUser', [(array) $user, $token]);
656 656
 
657 657
         return true;
658 658
     }
@@ -679,10 +679,10 @@  discard block
 block discarded – undo
679 679
         }
680 680
 
681 681
         // Generate a hash to match against the table.
682
-        $credentials['reset_hash'] = hash('sha1', config_item('auth.salt') .$credentials['code']);
682
+        $credentials['reset_hash'] = hash('sha1', config_item('auth.salt').$credentials['code']);
683 683
         unset($credentials['code']);
684 684
 
685
-        if (! empty($credentials['email']))
685
+        if ( ! empty($credentials['email']))
686 686
         {
687 687
             $credentials['email'] = strtolower($credentials['email']);
688 688
         }
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
         // Is there a matching user?
691 691
         $user = $this->user_model->find_by($credentials);
692 692
 
693
-        if (! $user)
693
+        if ( ! $user)
694 694
         {
695 695
             $this->error = lang('auth.reset_no_user');
696 696
             return false;
@@ -703,13 +703,13 @@  discard block
 block discarded – undo
703 703
             'reset_hash'   => null
704 704
         ];
705 705
 
706
-        if (! $this->user_model->update($user->id, $data))
706
+        if ( ! $this->user_model->update($user->id, $data))
707 707
         {
708 708
             $this->error = $this->user_model->error();
709 709
             return false;
710 710
         }
711 711
 
712
-        Events::trigger('didResetPassword', [(array)$user]);
712
+        Events::trigger('didResetPassword', [(array) $user]);
713 713
 
714 714
         return true;
715 715
     }
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
      * @param null $message
726 726
      * @return mixed
727 727
      */
728
-    public function changeStatus($newStatus, $message=null)
728
+    public function changeStatus($newStatus, $message = null)
729 729
     {
730 730
         // todo actually record new users status!
731 731
     }
@@ -742,14 +742,14 @@  discard block
 block discarded – undo
742 742
      * @param bool $allow_any_parent
743 743
      * @return mixed
744 744
      */
745
-    public function useModel($model, $allow_any_parent=false)
745
+    public function useModel($model, $allow_any_parent = false)
746 746
     {
747
-        if (! $allow_any_parent && get_parent_class($model) != 'Myth\Models\CIDbModel')
747
+        if ( ! $allow_any_parent && get_parent_class($model) != 'Myth\Models\CIDbModel')
748 748
         {
749 749
             throw new \RuntimeException('Models passed into LocalAuthenticate MUST extend Myth\Models\CIDbModel');
750 750
         }
751 751
 
752
-        $this->user_model =& $model;
752
+        $this->user_model = & $model;
753 753
 
754 754
         return $this;
755 755
     }
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
      */
822 822
     protected function rememberUser($user)
823 823
     {
824
-        if (! config_item('auth.allow_remembering'))
824
+        if ( ! config_item('auth.allow_remembering'))
825 825
         {
826 826
             log_message('debug', 'Auth library set to refuse "Remember Me" functionality.');
827 827
             return false;
@@ -840,13 +840,13 @@  discard block
 block discarded – undo
840 840
      * @param null $token
841 841
      * @return mixed
842 842
      */
843
-    protected function refreshRememberCookie($user, $token=null)
843
+    protected function refreshRememberCookie($user, $token = null)
844 844
     {
845 845
         $this->ci->load->helper('cookie');
846 846
 
847 847
         // If a token is passed in, we know we're removing the
848 848
         // old one.
849
-        if (! empty($token))
849
+        if ( ! empty($token))
850 850
         {
851 851
             $this->invalidateRememberCookie($user['email'], $token);
852 852
         }
@@ -856,7 +856,7 @@  discard block
 block discarded – undo
856 856
         // Save the token to the database.
857 857
         $data = [
858 858
             'email'   => $user['email'],
859
-            'hash'    => sha1(config_item('auth.salt') . $new_token),
859
+            'hash'    => sha1(config_item('auth.salt').$new_token),
860 860
             'created' => date('Y-m-d H:i:s')
861 861
         ];
862 862
 
@@ -864,13 +864,13 @@  discard block
 block discarded – undo
864 864
 
865 865
         // Create the cookie
866 866
         set_cookie(
867
-            'remember',                             // Cookie Name
868
-            $new_token,                             // Value
869
-            config_item('auth.remember_length'),    // # Seconds until it expires
867
+            'remember', // Cookie Name
868
+            $new_token, // Value
869
+            config_item('auth.remember_length'), // # Seconds until it expires
870 870
             config_item('cookie_domain'),
871 871
             config_item('cookie_path'),
872 872
             config_item('cookie_prefix'),
873
-            false,                                  // Only send over HTTPS?
873
+            false, // Only send over HTTPS?
874 874
             true                                    // Hide from Javascript?
875 875
         );
876 876
 
Please login to merge, or discard this patch.