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

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: here where i put the condition and here where it giving me hell

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

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...

Can you please describe (in words instead of code) what it is you are trying to do? In other words, if I was the programmer, what would you tell me in order for me to write the program without any further input from you?

if num is always 1, isn't your program stuck in an infinite loop?
Anyhow, I just want you to know that you can't possibly write a security module for your app in .Net. No matter what you do - keys, internet authentication, encrypted files or whatever .Net offers next to no protection for your code, including the code for the protection.
If you are serious about protecting your work, write a dll file VB 6 or a language without CLR and have that run authentication and a critical portion of your project in the same function/sub.

hi Reverend Jim ,

sorry if i did not post correctly. any how i will explain, i am planning to put a 25 alphanumeric protection key againts my software. i am able to generate the keys. but i also wanted to run a calculation method where if the results is a 0 then it is a valid key but if it is return 1 then its invalid. easy. now here is the issue, i keep getting 1 when i run the calculation condition. I cannot seem to generate num that is 0. the only way i could get 0 was do until num = 0 loop, but i cannot get the keys out for that zero result. I cant seem to generate keys accordingly. could you assist? do you need more explanation? i would more than glad to provide....

if num is always 1, isn't your program stuck in an infinite loop?
Anyhow, I just want you to know that you can't possibly write a security module for your app in .Net. No matter what you do - keys, internet authentication, encrypted files or whatever .Net offers next to no protection for your code, including the code for the protection.
If you are serious about protecting your work, write a dll file VB 6 or a language without CLR and have that run authentication and a critical portion of your project in the same function/sub.

maybe it is. but that is why i show the code. by the way do until loop does return a 0 but cant get the key correstponding to that result. any how yes i do know "Reflector". I will take your advise with a pinch of salt. But you could put it this way, i am just trying to make it difficult for the thief, if they want to do it and like you said, no matter how good your code is, it will be broken. Here the thing, its the target audience, its a custom software, so less people, not so famous, simple protection works. i just do not my client to have any ideas. Make it look grand and they will think it is hell of great. reality it just simple. SIMPLE is not my choice of word currently because i cant seem to solve the issue.

It seems to me that your code generator just creates a sequence of random characters. If you don't have an algorithm to generate specific sequences then how are you going to be able to tell what constitutes a valid key?

I would suggest 2 points:

1) Change Public Function GenerateCode() As Object to Public Function GenerateCode() As String 2) Change Public Function GetPID() to Public Function GetPID() as String Hope this helps

It seems to me that your code generator just creates a sequence of random characters. If you don't have an algorithm to generate specific sequences then how are you going to be able to tell what constitutes a valid key?

you are absolutely correct. that is why i am asking for idea or a sample algorithm or a way i can fix this?

I would suggest 2 points:

1) Change Public Function GenerateCode() As Object to Public Function GenerateCode() As String 2) Change Public Function GetPID() to Public Function GetPID() as String Hope this helps

thanks i have done the changes as suggested. thank you for the advise but to my luck that does not seem to be the issue.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.