PDA

View Full Version : [VB.NET] SerialGen (For Registering Product) [Source]



Server_CM
10-13-2014, 02:13 PM
Put this together quickly,
it can come in handy if your making a registration program
where the USER has to generate they're own key or you can use it to create a license system.

http://img809.imageshack.us/img809/8272/69413565.png


http://adfoc.us/405966411313

hellbegins
03-08-2015, 08:11 PM
The link is dead

Void
03-09-2015, 09:01 AM
Getting the MAC Address and Generating the Serial Number

The first step is to get the MAC address of the client's machine. This could be achieved by using the ManagementClass class located in the System.Management assembly. We have to add a reference to that assembly to our project, and import it into SecurityManager.vb, which will be the class in which we place the GetSerial() and CheckKey() functions. These two functions will be responsible for generating the serial number from the MAC address and checking whether the key entered by the user is valid. As a first step, we define the GetSerial() function as follows:



Public Function GetSerial() As Long
Dim mc As New ManagementClass("Win32_NetworkAdapterConfiguration ")
Dim mac As String = ""
'Getting network adapters collection
Dim moc As ManagementObjectCollection = mc.GetInstances

'Here we iterate over available network adapters,
'picking the first possible one
For Each mo As ManagementObject In moc
If mo.Item("IPEnabled") Then
mac = mo.Item("MacAddress").ToString
Exit For
End If
Next

mc.Dispose()

'This is a simple function that we use to get a serial out
'of our MAC address. Say that x is the MAC and y is the serial,
'the function would be y += x[i] + (i * 2) where i is the index
'of MAC address element.
Dim sum As Long = 0
Dim index As Integer = 1
For Each ch As Char In mac
If Char.IsDigit(ch) Then
sum += sum + Integer.Parse(ch) * (index * 2)
ElseIf Char.IsLetter(ch) Then
Select Case ch.ToString.ToUpper
Case "A"
sum += sum + 10 * (index * 2)
Case "B"
sum += sum + 11 * (index * 2)
Case "C"
sum += sum + 12 * (index * 2)
Case "D"
sum += sum + 13 * (index * 2)
Case "E"
sum += sum + 14 * (index * 2)
Case "F"
sum += sum + 15 * (index * 2)
End Select
End If

index += 1
Next

Return sum
End Function


This function will give us the unique serial number of each MAC address (not totally unique, but similar to hash function uniqueness).
Generating Activation Key from the Serial Number

The second step is to create the key generator which will generate the activation key from a given serial number. This generator will be placed in a class called KeyGenerator. This class will contain a function which will apply a simple mathematical function on the serial number to get the activation key. In this case, I will use the function f(x) = x2 + 53/x + 113 * (x/4).



Public Class KeyGenerator
Public Function GenerateKey(ByVal serial As Long) As Long
Dim x As Long = serial
Return x * x + 53 / x + 113 * (x / 4)
End Function
End Class

Back to SecurityManager.vb, we need to add one more function, which is CheckKey(). This function will take the activation key as a parameter, apply the key-generating function on the current MAC address, then compare the two keys to see whether they match or not.



Public Function CheckKey(ByVal key As Long) As Boolean
Dim x As Long = GetSerial()
Dim y As Long = x * x + 53 / x + 113 * (x / 4)
Return y = key
End Function

One important note left: do not place all of these classes in your client's solution! Remember that the key-generating class is only owned by you.
Happy coding!

Montrealer509
06-18-2017, 11:55 PM
thank u men

david5578
08-14-2017, 07:17 AM
link is dead.................

walaybani
01-06-2019, 12:34 PM
like where