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

The 'OTP' typed was wrong. #185

Open
OfficialJens opened this issue Mar 20, 2023 · 0 comments
Open

The 'OTP' typed was wrong. #185

OfficialJens opened this issue Mar 20, 2023 · 0 comments

Comments

@OfficialJens
Copy link

I tried this Google Authenticator but I keep getting the message that my OTP is wrong while this is the right one after I followed the tutorial correctly. Can someone tell me where the error is?

Web.php
`Route::middleware(['2fa'])->group(function () {
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::post('/2fa', function () {
return redirect(route('home'));
})->name('2fa');
});

Route::get('/complete-registration', [App\Http\Controllers\Auth\RegisterController::class, 'completeRegistration'])->name('complete.registration');`

User Model
` protected $fillable = [
'name',
'email',
'password',
'google2fa_secret',
];

protected $hidden = [
    'password',
    'remember_token',
];

protected $casts = [
    'email_verified_at' => 'datetime',
];

protected function google2faSecret(): Attribute
{
    return new Attribute(
        get: fn ($value) =>  decrypt($value),
        set: fn ($value) =>  encrypt($value),
    );
}`

Register Controller
` protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'google2fa_secret' => $data['google2fa_secret'],
]);
}

public function register(Request $request)
{
    $this->validator($request->all())->validate();

    $google2fa = app('pragmarx.google2fa');

    $registration_data = $request->all();

    $registration_data["google2fa_secret"] = $google2fa->generateSecretKey();

    $request->session()->flash('registration_data', $registration_data);

    $QR_Image = $google2fa->getQRCodeInline(
        config('app.name'),
        $registration_data['email'],
        $registration_data['google2fa_secret']
    );

    return view('google2fa.register', ['QR_Image' => $QR_Image, 'secret' => $registration_data['google2fa_secret']]);
}

public function completeRegistration(Request $request)
{
    $request->merge(session('registration_data'));

    return $this->registration($request);
}`
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

No branches or pull requests

1 participant