Skip to content

Commit f4d67db

Browse files
authored
Merge pull request #36 from thecodework/analysis-qxeYV3
Apply fixes from StyleCI
2 parents 5c8fcbe + dc64756 commit f4d67db

File tree

5 files changed

+24
-19
lines changed

5 files changed

+24
-19
lines changed

src/AuthenticatesUsersWith2FA.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Auth;
66
use Illuminate\Http\Request;
77
use OTPHP\TOTP;
8-
use Thecodework\TwoFactorAuthentication\TwoFactorAuthenticationServiceProvider;
98
use Validator;
109

1110
trait AuthenticatesUsersWith2FA
@@ -29,7 +28,7 @@ protected function authenticated(Request $request, $user)
2928
{
3029
if ($user->is_two_factor_enabled) {
3130
$request->session()->put('2fa:user:id', encrypt($user->id));
32-
$secret = getenv('HMAC_SECRET');
31+
$secret = getenv('HMAC_SECRET');
3332
$signature = hash_hmac('sha256', $user->id, $secret);
3433
Auth::logout();
3534

@@ -50,7 +49,7 @@ public function verifyToken(Request $request)
5049
{
5150
$userModel = TwoFactorAuthenticationServiceProvider::getUserModelInstance();
5251
// Pulling encrypted user id from session and getting user details
53-
$userId = $request->session()->get('2fa:user:id');
52+
$userId = $request->session()->get('2fa:user:id');
5453
$this->user = $userModel->find(decrypt($userId));
5554

5655
// If token is not valid then custom validation error message will be shown.
@@ -73,7 +72,7 @@ public function verifyToken(Request $request)
7372
'totp_token' => 'required|digits:6|valid_token',
7473
], $messages);
7574

76-
$secret = getenv('HMAC_SECRET');
75+
$secret = getenv('HMAC_SECRET');
7776
$signature = hash_hmac('sha256', $this->user->id, $secret);
7877
if ($validator->fails()) {
7978
return redirect('verify-2fa?signature=' . $signature)

src/Exceptions/TwoFactorAuthenticationExceptions.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
namespace Thecodework\TwoFactorAuthentication\Exceptions;
44

5-
class TwoFactorAuthenticationExceptions extends \Exception {
6-
5+
class TwoFactorAuthenticationExceptions extends \Exception
6+
{
77
/**
8-
* Column Not Found
9-
*
8+
* Column Not Found.
109
*/
1110
public static function columnNotFound()
1211
{
1312
$table = config('2fa-config.table');
13+
1414
return new static("Could not locate required column `two_factor_secret_key` or `is_two_factor_enabled` in `$table` table. Make sure the migrations ran properly.");
1515
}
16-
}
16+
}

src/Http/Controllers/TwoFactorAuthenticationController.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class TwoFactorAuthenticationController extends Controller implements TwoFactorA
1717
use AuthenticatesUsersWith2FA;
1818

1919
/**
20-
* User Model
20+
* User Model.
2121
*/
2222
protected $userModel;
2323

@@ -28,11 +28,13 @@ public function __construct()
2828
{
2929
$this->userModel = TwoFactorAuthenticationServiceProvider::getUserModelInstance();
3030
}
31+
3132
/**
3233
* Setup two factor authentication.
3334
*
3435
* @param \Illuminate\Http\Request
3536
* @param \Illuminate\Http\Response
37+
*
3638
* @throws \Thecodework\TwoFactorAuthentications\Exceptions\TwoFactorAuthenticationExceptions
3739
*/
3840
public function setupTwoFactorAuthentication(Request $request)
@@ -72,7 +74,7 @@ public function setupTwoFactorAuthentication(Request $request)
7274
*/
7375
public function enableTwoFactorAuthentication(Request $request)
7476
{
75-
$user = $this->userModel->find($request->user()->id);
77+
$user = $this->userModel->find($request->user()->id);
7678
$user->is_two_factor_enabled = 1;
7779
$user->update();
7880

@@ -97,7 +99,7 @@ public function enableTwoFactorAuthentication(Request $request)
9799
*/
98100
public function disableTwoFactorAuthentication(Request $request)
99101
{
100-
$user = $this->userModel->find($request->user()->id);
102+
$user = $this->userModel->find($request->user()->id);
101103
$user->is_two_factor_enabled = 0;
102104
$user->two_factor_secret_key = null;
103105
$user->update();
@@ -122,7 +124,7 @@ public function disableTwoFactorAuthentication(Request $request)
122124
public function verifyTwoFactorAuthentication(Request $request)
123125
{
124126
if ($request->session()->has('2fa:user:id')) {
125-
$secret = getenv('HMAC_SECRET');
127+
$secret = getenv('HMAC_SECRET');
126128
$signature = hash_hmac('sha256', decrypt($request->session()->get('2fa:user:id')), $secret);
127129

128130
if (md5($signature) !== md5($request->signature)) {
@@ -143,7 +145,8 @@ public function verifyTwoFactorAuthentication(Request $request)
143145
* @return string
144146
*/
145147
private function base32EncodedString($length = 30):
146-
string {
148+
string
149+
{
147150
return Base32::encode($this->strRandom($length));
148151
}
149152

@@ -155,7 +158,8 @@ private function base32EncodedString($length = 30):
155158
* @return string
156159
*/
157160
private function strRandom($length = 30):
158-
string{
161+
string
162+
{
159163
$string = '';
160164

161165
while (($len = strlen($string)) < $length) {

src/TwoFactorAuthenticationServiceProvider.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Thecodework\TwoFactorAuthentication;
44

5-
use Illuminate\Support\ServiceProvider;
65
use Illuminate\Database\Eloquent\Model;
6+
use Illuminate\Support\ServiceProvider;
77

88
class TwoFactorAuthenticationServiceProvider extends ServiceProvider
99
{
@@ -36,7 +36,7 @@ public function boot()
3636
}
3737

3838
/**
39-
* Get User moded defined in config file
39+
* Get User moded defined in config file.
4040
*
4141
* @return string
4242
*/
@@ -50,8 +50,10 @@ public static function determineUserModel(): string
5050
*
5151
* @return \Illuminate\Database\Eloquent\Model
5252
*/
53-
public static function getUserModelInstance(): Model {
53+
public static function getUserModelInstance(): Model
54+
{
5455
$userModelClassName = self::determineUserModel();
56+
5557
return new $userModelClassName();
5658
}
5759
}

tests/BaseTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ public function getEnvironmentSetUp($app)
7777
]);
7878
$app['config']->set('auth.providers.users.model', User::class);
7979
$app['config']->set('app.key', '6rE9Nz59bGRbeMATftriyQjrpF7DcOQm');
80-
$app['config']->set('2fa-config.table','users');
80+
$app['config']->set('2fa-config.table', 'users');
8181
}
8282
}

0 commit comments

Comments
 (0)