I need login into my application using MFA after I login with user ID and password. We have DUO (for login to our servers).
Do you have any sample code (VB) which I can use in my application?
Namespace Forza
Partial Public Class pagGoogleAuthenticator
Inherits System.Web.UI.Page
Private Property AuthenticationCode As String
Get
If ViewState("AuthenticationCode") IsNot Nothing Then Return ViewState("AuthenticationCode").ToString().Trim()
Return String.Empty
End Get
Set(ByVal value As String)
ViewState("AuthenticationCode") = value.Trim()
End Set
End Property
Private ReadOnly Property AuthenticationTitle As String
Get
Return "Ankush"
End Get
End Property
Private Property AuthenticationBarCodeImage As String
Private Property AuthenticationManualCode As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not Page.IsPostBack Then
lblResult.Text = String.Empty
lblResult.Visible = False
GenerateTwoFactorAuthentication()
imgQrCode.ImageUrl = AuthenticationBarCodeImage
lblManualSetupCode.Text = AuthenticationManualCode
lblAccountName.Text = AuthenticationTitle
End If
End Sub
Protected Sub btnValidate_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim pin As String = txtSecurityCode.Text.Trim()
Dim status As Boolean = ValidateTwoFactorPIN(pin)
If status Then
lblResult.Visible = True
lblResult.Text = "Code Successfully Verified."
Else
lblResult.Visible = True
lblResult.Text = "Invalid Code."
End If
End Sub
Public Function ValidateTwoFactorPIN(ByVal pin As String) As Boolean
Dim tfa As TwoFactorAuthenticator = New TwoFactorAuthenticator()
Return tfa.ValidateTwoFactorPIN(AuthenticationCode, pin)
End Function
Public Function GenerateTwoFactorAuthentication() As Boolean
Dim guid As Guid = guid.NewGuid()
Dim uniqueUserKey As String = Convert.ToString(guid).Replace("-", "").Substring(0, 10)
AuthenticationCode = uniqueUserKey
Dim result As Dictionary(Of String, String) = New Dictionary(Of String, String)()
Dim tfa As TwoFactorAuthenticator = New TwoFactorAuthenticator()
Dim setupInfo = tfa.GenerateSetupCode("Complio", AuthenticationTitle, AuthenticationCode, 300, 300)
If setupInfo IsNot Nothing Then
AuthenticationBarCodeImage = setupInfo.QrCodeSetupImageUrl
AuthenticationManualCode = setupInfo.ManualEntryKey
Return True
End If
Return False
End Function
End Class
End Namespace
But I still can't understand what I have to do else. I have login page where I put user name and password and what I have to add after.
This is my code behind from login page:
Dim loginUsername As String = Login1.UserName
Dim loginPassword As String = Login1.Password
Dim strSQL As String = "SELECT ID AS VAL, UserName, Password FROM tblUser WHERE (UserName = '" & funCheckChar(loginUsername)
strSQL &= "') AND (Password='" & funCheckChar(loginPassword) & "')"
intUserID = Val(ExecSQLReturnVal(strSQL))
If intUserID > 0 Then
e.Authenticated = True
Else
e.Authenticated = False
End If
As I understand I have to add something here:
If intUserID > 0 Then
e.Authenticated = True
' add MFA here
Else
e.Authenticated = False
End If
Thanks
Alex