Last active
December 29, 2020 19:49
-
-
Save ezekg/64415066cb1c9e7409a3017e85c10ca2 to your computer and use it in GitHub Desktop.
Example of VB/VBA license key validation using https://keygen.sh and Visual Basic. If you're using this to add licensing an Excel document, you may need to activate "Microsoft Scripting Runtime" in Excel under "Tools" and then "References." See this tutorial on making HTTP requests from within Excel: http://excelerator.solutions/2017/08/28/excel…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Call this function from a dialog that prompts for the customer's | |
' license key, or however you prefer. Call as often as needed. | |
Function ValidateLicenseKey(licenseKey As String) | |
' TODO: Update this to your Keygen account ID | |
Dim accountId As String | |
accountId = "demo" | |
Dim req As Object | |
req = CreateObject("MSXML2.XMLHTTP") | |
With req | |
.Open "POST", "https://api.keygen.sh/v1/accounts/" & accountId & "/licenses/actions/validate-key", False | |
.setRequestHeader "Content-Type", "application/json" | |
.send "{ ""meta"": { ""key"": """ & licenseKey & """ } }" | |
End With | |
Dim res As String | |
res = req.ResponseText | |
Dim json As Dictionary | |
json = JsonConverter.ParseJson(res) | |
If json.Exists("errors") = True Then | |
' TODO: Handle fatal HTTP error (no internet access, etc.) | |
End If | |
Dim meta As Dictionary | |
meta = json.Item("meta") | |
If meta.Item("valid") = True Then | |
' TODO: Handle valid license key (possibly do nothing) | |
Else | |
' TODO: Handle invalid license key | |
End If | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment