Classic ASP Requires Chilkat v11.0.0+
Classic ASP
Check an SMS verification code with Twilio Verify
See more Twilio Examples
After the user enters the SMS code, retrieve the VE verification SID saved when you started the verification. Send that SID and the entered code to the same Verify Service. Keep the code as text so a leading zero survives.
Mark the phone number on that pending attempt as verified only when Twilio returns status=approved. A pending check leaves the number unverified. Twilio can return HTTP 404 after expiration, approval, or exhaustion of check attempts. Keep a successful result in your application so it can be used after Twilio removes the verification.
Chilkat Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0
' Assumes Chilkat is unlocked. See Global Unlock Sample.
' Obtain these credentials from the application's private configuration.
set http = Server.CreateObject("Chilkat.Http")
http.RequireSslCertVerify = 1
http.BasicAuth = 1
http.Login = "YOUR_API_KEY_SID"
http.Password = "YOUR_API_KEY_SECRET"
' Both requests use the same Verify Service SID (VA...).
set url = Server.CreateObject("Chilkat.StringBuilder")
success = url.Append("https://verify.twilio.com/v2/Services/")
success = url.Append("YOUR_VERIFY_SERVICE_SID")
success = url.Append("/VerificationCheck")
set req = Server.CreateObject("Chilkat.HttpRequest")
req.HttpVerb = "POST"
req.ContentType = "application/x-www-form-urlencoded"
' Load the saved SID for this user's pending attempt. Take only the code from user input.
verificationSid = "SAVED_VERIFICATION_SID"
enteredCode = "CODE_ENTERED_BY_USER"
req.AddParam "VerificationSid",verificationSid
req.AddParam "Code",enteredCode
set resp = Server.CreateObject("Chilkat.HttpResponse")
success = http.HttpReq(url.GetAsString(),req,resp)
If (resp.StatusCode = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( "No response from Twilio. Check connectivity and TLS settings.") & "</pre>"
Response.End
End If
If (resp.StatusCode = 404) Then
Response.Write "<pre>" & Server.HTMLEncode( "No active verification found. Check the service and verification SIDs.") & "</pre>"
Response.End
End If
set result = Server.CreateObject("Chilkat.JsonObject")
parsed = result.Load(resp.BodyStr)
If ((success <> 1) Or (resp.StatusCode < 200) Or (resp.StatusCode >= 300)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Twilio returned HTTP " & resp.StatusCode) & "</pre>"
If ((parsed = 1) And (result.JsonTypeOf("code") = 2)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Twilio error code: " & result.IntOf("code")) & "</pre>"
End If
Response.End
End If
If ((parsed <> 1) Or (result.JsonTypeOf("status") <> 1)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Verification status missing from the response.") & "</pre>"
Response.End
End If
status = result.StringOf("status")
If (status = "approved") Then
' Record success for the user and phone number associated with verificationSid.
Response.Write "<pre>" & Server.HTMLEncode( "Phone number verified.") & "</pre>"
Else
If (status = "pending") Then
Response.Write "<pre>" & Server.HTMLEncode( "Code not accepted. Check the digits and enter the code again.") & "</pre>"
Else
Response.Write "<pre>" & Server.HTMLEncode( "Phone number unverified. Verification status: " & status) & "</pre>"
End If
End If
%>
</body>
</html>