Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Custom recovery codes #555

Closed
wants to merge 2 commits into from

Conversation

tomwelch
Copy link

Hi all,

Recently I had a situation where I needed to choose a different length for the 2FA recovery codes and provide them as lowercase. As RecoveryCode::generate() is called statically in TwoFactorAuthenticatable, EnableTwoFactorAuthentication and GenerateNewRecoveryCodes I had to extend those classes to be able to call my own RecoveryCode class.

This PR aims to fix that paper cut by allowing developers to (optionally) define how recovery codes are generated by calling a new RecoveryCode::generateRecoveryCodeUsing() method and providing a callback. For example:

RecoveryCode::generateRecoveryCodeUsing(function () {
    return Str::lower(Str::random(6).'-'.Str::random(6));
});

Another way so solve this issue might be to bind the RecoveryCode class to the container with a contract so it can be rebound, but this felt simpler and is a pattern used in other places within Laravel (ResetPassword::createUrlUsing() for example) however happy to go that route if it is preferred.

@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants