Hi Resource18,
Follow the steps to implement two factor authentication in your VB.Net project.
https://docs.microsoft.com/en-us/aspnet/web-forms/overview/security/create-an-aspnet-web-forms-app-with-sms-two-factor-authentication
Change the below code.
Manage.aspx.vb
Protected Sub Page_Load() Handles Me.Load
Dim manager = Context.GetOwinContext().GetUserManager(Of ApplicationUserManager)()
HasPhoneNumber = String.IsNullOrEmpty(manager.GetPhoneNumber(User.Identity.GetUserId()))
' Enable this after setting up two-factor authentientication
PhoneNumber.Text = If(manager.GetPhoneNumber(User.Identity.GetUserId()), String.Empty)
TwoFactorEnabled = manager.GetTwoFactorEnabled(User.Identity.GetUserId())
LoginsCount = manager.GetLogins(User.Identity.GetUserId()).Count
Dim authenticationManager = HttpContext.Current.GetOwinContext().Authentication
If Not IsPostBack Then
' Determine the sections to render
If HasPassword(manager) Then
ChangePassword.Visible = True
Else
CreatePassword.Visible = True
ChangePassword.Visible = False
End If
' Render success message
Dim message = Request.QueryString("m")
If message IsNot Nothing Then
' Strip the query string from action
Form.Action = ResolveUrl("~/Account/Manage")
SuccessMessage = If(message = "ChangePwdSuccess", "Your password has been changed.",
If(message = "SetPwdSuccess", "Your password has been set.",
If(message = "RemoveLoginSuccess", "The account was removed.",
If(message = "AddPhoneNumberSuccess", "Phone number has been added",
If(message = "RemovePhoneNumberSuccess", "Phone number was removed", String.Empty)))))
SuccessMessagePlaceHolder.Visible = Not String.IsNullOrEmpty(SuccessMessage)
End If
End If
End Sub
Account/TwoFactorAuthenticationSignIn.aspx.vb
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim userId = signinManager.GetVerifiedUserId()
If userId Is Nothing Then
Response.Redirect("/Account/Error", True)
End If
Dim userFactors = manager.GetValidTwoFactorProviders(userId)
Providers.DataSource = userFactors.Select(Function(x) x).ToList()
Providers.DataBind()
End If
End Sub
App_Start\IdentityConfig.vb
Public Class SmsService
Implements IIdentityMessageService
Public Function SendAsync(message As IdentityMessage) As Task Implements IIdentityMessageService.SendAsync
' Plug in your SMS service here to send a text message.
Dim Twilio = New Twilio.TwilioRestClient(ConfigurationManager.AppSettings("SMSSID"), ConfigurationManager.AppSettings("SMSAuthToken"))
Dim result = Twilio.SendMessage(ConfigurationManager.AppSettings("SMSPhoneNumber"), message.Destination, message.Body)
Trace.TraceInformation(result.Status)
Return Task.FromResult(0)
End Function
End Class