Android Example Simple Code Module to implemente a License file using StringFunctions Encrypt

B4X:
Type=StaticCode
Version=6.48
ModulesStructureVersion=1
B4A=true
@EndOfDesignText@
'******************************************************************************************************
'*                         Sub to be Placed in Main Activity to check the Licence
'*                               Libraries needed: Phone and StringFnctions
'*                                      (c)2016 Pedro Miguel Caldeira
'******************************************************************************************************
'* Parameters to Pass to CheckLicense Sub : Application Name
'*                                             Application Version
'*                                             Expiry Date
'*                                             Flag to Show Device ID
'*                                             Flag to Check Expiry Date
'******************************************************************************************************
'*                                                                                                    *
'******************************************************************************************************
'
'Sub GetLicense
'
'    Dim tmpLic As String
'
'    If File.Exists(File.DirDefaultExternal,"license") Then
'        tmpLic=File.ReadString(File.DirDefaultExternal,"license")
'    Else
'        Licensing.CheckLicense("","","","",True, False)
'    End If
'
'    If Licensing.CheckLicense("Appname","AppVersion","31/12/2000",tmpLic, False, False) = True Then
'        ' Licensed
'    Else
'        ' Demo Version
'    End If
'   
'End Sub
'******************************************************************************************************
'*                                                                                                    *
'******************************************************************************************************
'
Sub Process_Globals
   
    Dim ph As Phone
    Dim StrF As StringFunctions

End Sub


Sub CheckLicense(ProductName As String,Productversion As String, ExpiryDate As String, Lic2Compare As String, ShowID As Boolean, CheckDate As Boolean) As Boolean
   
    Dim LicValue As String
    Dim IDValue As String
    Dim Today As String
    StrF.Initialize
   
    'Get The unique Android Compilaton Value
    IDValue=ph.GetSettings("android_id")
   
    'If the Parameter ShowID is set to True, then dont check validity, but show device ID and return False
    'This Parameter is only to allow us to generate a valid license file to give the costumer
    'A Separate App must be created to generate licenses with the same parameters of this sub
    'Of course that this code can be used for that
    If ShowID = True Then
        Msgbox("Device ID :" & IDValue,"Device Indentification")
        Return False
    End If
   
    ' If Any of the Parameters are empty, return False
    If ProductName="" Or Productversion="" Or ExpiryDate="" Then
        Return False
    End If
   
    ' If the checkDate Parameter is True then Check the Expiry date against today date, if equal or greater, return false
    If CheckDate=True Then
       
        DateTime.DateFormat="dd/MM/yyyy"
        Today=DateTime.Date(DateTime.Now)
       
        If DateTime.DateParse(ExpiryDate) => DateTime.DateParse(Today) Then
            Return False
        End If
   
    End If
    ' Assemble a string composed of the Main Sub Parameters
    LicValue=IDValue & ProductName & Productversion & ExpiryDate
   
    'Perform a Basic encryptation of the assembled String, Lic2Compare Parameter must be equal to return True
    LicValue=StrF.Encrypt(LicValue)
   
    'Check both Vars to see if License is Valid
    If Lic2Compare = LicValue Then
        Return True
    Else
        Return False
    End If
   
End Sub
 

Attachments

  • Licensing.bas
    3.5 KB · Views: 336
Top