I'm using this code from GitHub
https://github.com/as08/ClassicASP.TwoFactorAuthentication
I downloaded the demo site, installed what I needed on the server and everything works perfectly. The demo site has a lot of code so I broke it down into the two components that are shown on the Github page 1)Generating a secret key and QR code 2) Validating a verification code.
I made 2 very barebones basic asp pages
index.asp
<%
Dim TwoFA : Set TwoFA = Server.CreateObject("ClassicASP.TwoFactorAuthentication")
TwoFA.SecretKeyLength(20)
TwoFA.HashMode("SHA1")
TwoFA.totpSize(6)
RecoveryPasswordLength = 18
Dim SecretKey, RecoveryPassword, GenerateQR
SecretKey = TwoFA.GenerateSecretKey()
RecoveryPassword = TwoFA.RecoveryPassword(RecoveryPasswordLength)
response.write("Secret Key: " & secretKey & "<br>")
response.write("Recovery Password: " & RecoveryPassword & "<br />")
' Generate the QR code
GenerateQR = "<img src=""https://chart.googleapis.com/chart" &_
"?chs=320x320" &_
"&chld=H|0" &_
"&cht=qr" &_
"&chl=" & Server.URLencode("otpauth://totp/test@test.com" &_
"?secret=" & SecretKey &_
"&issuer=examplesite.com" &_
"&algorithm=SHA1" &_
"&digits=6" &_
"&period=30") & "&choe=UTF-8"" " &_
"class=""img-fluid border-info border mt-4 QRframe"" " &_
"width=""320px"" height=""320px"">"
Set TwoFA = Nothing
%>
<%=GenerateQR%>
Validate.asp
<%
Dim TwoFA : Set TwoFA = Server.CreateObject("ClassicASP.TwoFactorAuthentication")
TwoFA.SecretKeyLength(20)
TwoFA.HashMode("SHA1")
TwoFA.totpSize(6)
TOTP = request("totp")
response.write(totp & "<br />")
If TwoFA.Verify("EDSLKFQENTEFPATYN5LAZ5BCGD2UOR4R",cStr(TOTP)) Then
' Valid Time-based One-time Password (TOTP)
response.write("valid")
Else
' Invalid TOTP
response.write("invalid")
End If
Set TwoFA = Nothing
%>
To test, I went to my index.asp page and generated a QRcode and set that up in Microsoft Authenticator. I then took the secret key and hardcoded it into the validate page's verify call. Then I went into Authenticator and got the code and tested it by going to validate.asp?totp=123456
. No matter what I do, I can't get this to work. I always get the response.write("invalid")
result.
Why is this not returning a valid response even though I'm typing in the right 6 digit code using the right secret key?