Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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
 
[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
 
[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 25-Sep-11 2:54am
Comments
SAKryukov at 25-Sep-11 12:12pm
   
What is that return value 0 or 1?
--SA
theonebit at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 565
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 25 Sep 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100