I've set up 2 factor authentication in my .net core mvc application using the guide from here This is all working fine however it relies on the user going into their account and setting up 2FA. Is there any way I can force the user to do this so all users must use 2FA?
One ways is during login you check whether user have set the 2FA by :
var user = await _userManager.FindByEmailAsync(Input.Email);
var twoFactorEnabled = user.TwoFactorEnabled;
If it is false , you can then redirect user to config the 2FA page(./Manage/TwoFactorAuthentication
) , after user set the 2FA and enable 2FA , TwoFactorEnabled
in AspNetUsers
table will be True
and then during the login process , identity will automatically redirect user to ./LoginWith2fa
page for 2FA login if current user's TwoFactorEnabled
value is true .