Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have a problem. I have been programming an activation type of security protection for my

software but i ran into problems when i try to generate an alphanumeric key with

conditions. i cant seem to be able to make the keys to be valid with the condition.

Basically i can get the 25 keys but all of them seem to be returning 1 (ones) instead of 0

(zero which what i want. below is my sample code may be someone can tell me what i am doing

wrong, by the way i did google, woogle,bing, bang, yahoo, yadoo etc but no go.

code: generate the keys

VB
[CODE]
Public Function GenerateCode() As Object
        Dim IntRnd As Object
        Dim IntStep As Object
        Dim StrName As Object
        Dim IntNameLength As Object
        Dim IntLength As Object
        Dim StrInputString As Object


      'set the char needed
  StrInputString = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"

   
     IntLength = Len(StrInputString)

     
'set the length
   IntNameLength = 25

      
  Randomize()

     
   StrName = ""

    
    For IntStep = 1 To IntNameLength
            IntRnd = Int((IntLength * Rnd()) + 1)
            StrName = StrName & Mid(StrInputString, IntRnd, 1)
        Next

        Return StrName
    End Function
[/CODE]


code: here where i put the condition and here where it giving me hell

VB
[CODE]

Public Function GetPID()

        Dim pid As String = String.Empty
        Dim digitalPid As Byte()
        Dim sequenceNumber As Integer = 0
        Dim upgradeFlag As Boolean = False
        Dim isOem As Boolean = False
        Dim oemID As String = Nothing
        Dim builder As New StringBuilder(&H18, &H18)
        digitalPid = New Byte(&H100 - 1) {}
        Buffer.BlockCopy(BitConverter.GetBytes(digitalPid.Length), 0, digitalPid, 0, 4)
        Dim num As Integer
 dim key as string 
redo1: key = generatecode()
        num = setcon(key, con1, con2)

if num = 0 then
return key 
else
goto redo1:
end if

      End Function

[/CODE]
the damn thing keeps returning 1 instead of 0. I do know i can simply change to 1 and be

off the issue. but if is that easy to generate 1 then isnt it easy just to break it. oh yeah

the whole thing hangs when i generate the code???
if i loop it, its able to get a 0 but i cant take the key thats in the loop??
any idea or comment is much appreciated, i do not need the coding just the logic should do,

i should be able to find my way around...
Posted
Comments
Sergey Alexandrovich Kryukov 25-Sep-11 12:12pm    
What is that return value 0 or 1?
--SA
theonebit 26-Sep-11 0:24am    
when i loop such as


Collapse | Copy Code
do until num = 0
key = generatecode()
num = setcon(key, con1, con2)
loop

return num


i will get a zero but i need the key to that zero num?
how do i get the key

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900