1
0
mirror of https://github.com/delight-im/PHP-Auth.git synced 2025-07-30 21:00:13 +02:00

Implement 'prepareTwoFactorViaEmail' using 'prepareTwoFactor'

This commit is contained in:
Marco
2024-04-04 19:42:23 +02:00
parent ea7b1208ad
commit b0965525de

View File

@@ -1794,6 +1794,26 @@ final class Auth extends UserManager {
return [ $phoneNumber, $otpValue ];
}
/**
* Prepares the setup of two-factor authentification with one-time passwords sent via email
*
* After performing this step, a one-time password will have to be delivered to the user via email and then be requested from the user for verification
*
* When the user has entered the one-time password from the email afterwards, call {@see enableTwoFactorViaEmail} with that one-time password
*
* @return string[] an array with the email address at index zero and the one-time password to be sent (but not otherwise displayed to the user) at index one
* @throws TwoFactorMechanismAlreadyEnabledException if this method of two-factor authentification has already been enabled
* @throws NotLoggedInException if the user is not currently signed in
* @throws TooManyRequestsException if the number of allowed attempts/requests has been exceeded
* @throws AuthError if an internal problem occurred (do *not* catch)
*/
public function prepareTwoFactorViaEmail() {
$this->prepareTwoFactor(self::TWO_FACTOR_MECHANISM_EMAIL, null, null);
$otpValue = $this->generateAndStoreRandomOneTimePassword($this->getUserId(), self::TWO_FACTOR_MECHANISM_EMAIL);
return [ $this->getEmail(), $otpValue ];
}
/**
* Prepares the setup of two-factor authentification via a specified mechanism
*