Validate License Via Internet from VB App

Posted on 2007-03-30
Medium Priority
Last Modified: 2008-02-01
I have an already existing VB app, that I can modify and add some code, that I wanted to deploy, but need to come up with a solution to validate on-line to allow the application to work. Basically, to validate if a client has paid, let's say, the key would be turned on, and if not, the app key would be turned off.  I can logically create the code, but need some ground-level advice on how and what (and some code) to do this.  What is involved.  Conceptually it seems simple, I have a list of clients, with a flag of 1 or 0 (on/off).  I can update this value at will.  The client app upon runtime, or say every 30 days, goto a designated site, look up the client, see the value, and let it do its thing from there.  Any ideas on what the best approach is, and how to do something like this?  I'm creating a service model for this app.  Thanks!
Question by:rsp05
  • 3
  • 2
  • 2
  • +1
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 18828016
1/ need to have a website that is DB enabled.. costs more
1.1 Create a form there that accepts a UserID as input and returns a passcode to the application.  The VB Web controls should be able to do this.
1.2 The application then compares the returned passcode to the locally stored one.
1.3 If you will be tying this to a machine, then you need a mechanism for identifing each box. So the first time and install is done on a PC, the user will have to enter some detail of the box and get back a valid passcode.
1.4 A hardware key would be best for this latter part as it's more secure, a licence can be shared around the office (one at a time though).  Talking dollars though.

2/ If website is not DB & scripting enabled, then you will have to download a textfile, perhaps based upon the userid , open it and compare contents with passcode.
2.1 this is probably a little more difficult to manage but when licence expires, you can change the webfile so the passcode no longer matches.
2.2 I wouldnt just delete the file as then the user will get a "file not found" error which could be just because the internet is don for them.

my 2c worth.
LVL 13

Expert Comment

ID: 18830851

the way i would design it, is not to disable the code,
but to remove the code

if you have some code disabled, or a menu item disabled or so,
this can be easily reverse engineered.

when the code is not there (it is in a dll that sits on your server)

it needs to be downloaded before the user can execute the code.

and when can the user download it?
with the right code :)
LVL 70

Expert Comment

by:Éric Moreau
ID: 18831801
that would mean that the application could not be used offline!
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 13

Expert Comment

ID: 18831828

that would mean the user would validate online, and then the pc can be taken offline

Author Comment

ID: 18834304
Thanks, all for reply.
Mark is right, although I would have the app validated every say, 30 days (+ a grace period), and the app would be used offline.  I would require that the user app have access to the internet.
I will study robberbaron's interesting solutions.

I was going to have the validation code compiled in the vb app, and the client info would be in the registry (where it is now).  What is some code sample to goto a web site, read a file, and compare values. Tx

Author Comment

ID: 18868608
robberbaron: If I went w/option 2, how would I reference the textfile, just by supplying the path to url?.  I would need to upload a textfile to the site, and call it there?  Code ideas?  Thx
LVL 32

Accepted Solution

Robberbaron (robr) earned 500 total points
ID: 18874635
1/ You would need to assign each user a licence number xxyyzz (no surprise there) when they paid for app.

2/ You upload a Text or binary file to your web server, named like xxyyyzz.lic.  It can be a binary format decided by you and has expiry date etc encoded within.

3/ When user installs app on their system , they enter the license number. App saves to registry.

4/ When app runs, it gets license number from registry then attempts to connect to INET and retrieve the license file xxyyzz.lic from your website.  The app saves the lic file or just opens stream and decodes data.  App then decides if it is currently licensed to run.

5/ When lic expires, you can delete the lic file from web or simply copy an invalid one in its place. I like the latter as the user will then get a License invalid error rather than lic not found.

Here is some code i once used to download a couple of files from net using the Internet control

    Dim strURL As String, x As CheckBox
    Dim savefile As String, fln As Long
    Dim b() As Byte
    For Each x In chkGethistory
        If x.Value = vbChecked Then
            ' Set the strURL to a valid address.
            Select Case x.index
                Case 0  'Saturday
                    strURL = URLHistorySat
                    savefile = FileHistorySat
                    'picOut.Print "/"
                    picOut.Print "Sat Hist"
                Case 1  'wednay
                    strURL = URLHistoryWed
                    savefile = FileHistoryWed
                    'picOut.Print "/"
                    picOut.Print "Wed Hist"
                Case 2  '
                    'strURL = URLHistoryPball
            End Select
             b() = Inet1.OpenURL(strURL, icByteArray)
            picOut.Print "/";
            fln = FreeFile
            Open savefile For Binary Access Write As #fln
            Put #fln, , b()
            Close #fln
            picOut.Print "} saved"

        End If

    Next x

Author Comment

ID: 18878126
robberbaron:  Definately enough to go on.  Appreciate the logic which I am using.  Found some alternate code to accomplish this, but you definately gave me 99% of what I needed - Thanks so much!  I'll post it here for future users:

Private Declare Function URLDownloadToFile Lib "urlmon" _
   Alias "URLDownloadToFileA" _
  (ByVal pCaller As Long, _
   ByVal szURL As String, _
   ByVal szFileName As String, _
   ByVal dwReserved As Long, _
   ByVal lpfnCB As Long) As Long
Private Const ERROR_SUCCESS As Long = 0
Private Const INTERNET_FLAG_RELOAD As Long = &H80000000

Private Sub Form_Load()

   Command1.Caption = "Download File"
End Sub

Private Sub Command1_Click()

   Dim sSourceUrl As String
   Dim sLocalFile As String
   Dim hfile As Long
   sSourceUrl = "http://www.myurl/client1.lic"
   sLocalFile = "c:\localtemp.lic"
   If DownloadFile(sSourceUrl, sLocalFile) Then
      hfile = FreeFile
      Open sLocalFile For Input As #hfile
         msg = Input$(LOF(hfile), hfile)
         MsgBox (msg)
      Close #hfile
   End If

End Sub

Public Function DownloadFile(sSourceUrl As String, _
                             sLocalFile As String) As Boolean
  'Download the file. BINDF_GETNEWESTVERSION forces
  'the API to download from the specified source.
  'Passing 0& as dwReserved causes the locally-cached
  'copy to be downloaded, if available. If the API
  'returns ERROR_SUCCESS (0), DownloadFile returns True.
   DownloadFile = URLDownloadToFile(0&, _
                                    sSourceUrl, _
                                    sLocalFile, _
                                    BINDF_GETNEWESTVERSION, _
                                    0&) = ERROR_SUCCESS
End Function

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Six Sigma Control Plans

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question