Skip to content

Commit ccc5511

Browse files
authored
Adding context length configuration for 2FA to ensure better security standards (#568)
* Update TwoFactorAuthenticationProvider.php Added secret length option to generate secret key * Update EnableTwoFactorAuthentication.php Consume a new option that can be set from config files to ensure basic required length for 2FA security * Update TwoFactorAuthenticationProvider.php Update contract to reflect new security standard in 2FA * Update TwoFactorAuthenticationProvider.php Reverted Contract mandatory parameter to avoid backward incompatibility * Fixing typo TwoFactorAuthenticationProvider.php * Switched case in EnableTwoFactorAuthentication.php * Update TwoFactorAuthenticationProvider.php
1 parent a3cae72 commit ccc5511

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/Actions/EnableTwoFactorAuthentication.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ public function __construct(TwoFactorAuthenticationProvider $provider)
3737
public function __invoke($user, $force = false)
3838
{
3939
if (empty($user->two_factor_secret) || $force === true) {
40+
41+
$secretLength = (int) config('fortify-options.two-factor-authentication.secret-length', 16);
42+
4043
$user->forceFill([
41-
'two_factor_secret' => encrypt($this->provider->generateSecretKey()),
44+
'two_factor_secret' => encrypt($this->provider->generateSecretKey($secretLength)),
4245
'two_factor_recovery_codes' => encrypt(json_encode(Collection::times(8, function () {
4346
return RecoveryCode::generate();
4447
})->all())),

src/TwoFactorAuthenticationProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ public function __construct(Google2FA $engine, Repository $cache = null)
3838
/**
3939
* Generate a new secret key.
4040
*
41+
* @param int $secretLength
4142
* @return string
4243
*/
43-
public function generateSecretKey()
44+
public function generateSecretKey(int $secretLength = 16)
4445
{
45-
return $this->engine->generateSecretKey();
46+
return $this->engine->generateSecretKey($secretLength);
4647
}
4748

4849
/**

0 commit comments

Comments
 (0)