Register Code

Blitz3D Forums/Blitz3D Programming/Register Code

wizzlefish(Posted 2004) [#1]
I'm making a shareware game, and you need a code to open it. How would I make a random code the first time the program was run, save it, and keep the same code every time that specific copy of the program is run?


Zenith(Posted 2004) [#2]
That sort of defeats the purpose behind it. :D


Rimmsy(Posted 2004) [#3]
Shareware games by their very nature are just one level versions of the full game that can be run as many times as you want on as many computers are you want. I think you must be thinking of something similar...

If you really wanted to do what you said you could just randomly generate a number and save it to a file.
; running the game
if filesize("number.key")=0
   ; this is the first time the game has been run
   f=writefile("number.key")
   writeint f,rand(9999999999)
   closefile f
else
   ; this is the second time the game has been run
endif



WolRon(Posted 2004) [#4]
Rims method doesn't prevent the user from reading the number key file, if that's a concern.


Rimmsy(Posted 2004) [#5]
mmm, then you'll have to encrypt it or even write to the registry which people, I among them, do not like.


wizzlefish(Posted 2004) [#6]
Oh well. I could just modify each copy of the game I give out. I'll make the code extremely long, something like:

899761TFFG6DS3VBK-PXZ1255KH-DWQ298LL9-QWERTY23-JJFORD256

There we go. Now I just need one billion unique codes.... :)


Rimmsy(Posted 2004) [#7]
have a look at rob's work: http://blitzbasic.com/codearcs/codearcs.php?code=992


Erroneouss(Posted 2004) [#8]
Run:
bob$="hi"           ;the username
joe$=keygen$(bob$)  ;creates the password
Print joe$          ;shows the password 
;---------------------------------------------------

Function keygen$(name$)

	; change v$ to as many or few random or unrandom letters, numbers, characters whatever
	; this is what the key is going to be made out of
	; You can have duplicates all over the place if you want, it's up to you!
	; This is one part that will make your keys unique to other people using this program
	; e.g. v$="I1D9U0AJ5PFWIN1TR3EKLWZID42HU7KL8S6LTBN9VMCXOF6T46GY3JHIE9T7VTLFDEQ3Y38P"

	v$ = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"

	tname$ = name$

	; make name longer if necessary
	; again adjust this to make your keys unique

	namel = 20
	Repeat
		If Len(tname) <= namel
			temp$ = ""
			For n = 1 To Len(tname)
				temp = temp + Chr(Asc(Mid(tname, n, 1)) + 1)
			Next
			tname = tname + temp
		EndIf
	Until Len(tname) > namel

	; this bit makes sure that you don't get any obvious repetitions over the 20 character key
	For n = 5 To 100 Step 5
		If Len(tname) = n Then tname = tname + "~"
	Next

	; create encrypt string
	encrypt$ = ""
	For n = 0 To 19
		encrypt = encrypt + Chr(1)
	Next
	ee = 1

	; over load encrypt 30 times
	; change this to make your keys unique further

	For l = 1 To 30

		For n = 1 To Len(tname)
			a = Asc(Mid(tname, n, 1))
			a = a - 32

			temp$ = ""

			For nn = 1 To 20
				tl = Asc(Mid(encrypt, nn, 1))
				If nn = ee Then temp = temp + Chr(tl + a Mod 256)Else temp = temp + Chr(tl)
			Next
			encrypt = temp
			ee = ee + 1
			If ee = 20 Then ee = 1
		Next

	Next

	; suck out the key
	encrypted$ = ""
	For ee = 1 To 20
		e = Asc(Mid(encrypt, ee, 1))Mod Len(v)
		If e = 0 Then e = 1
		encrypted = encrypted + Mid(v, e, 1)
	Next

	; format the key with -'s
	encrypted = Mid(encrypted, 1, 5) + "-" + Mid(encrypted, 6, 5) + "-" + Mid(encrypted, 11, 5) + "-" + Mid(encrypted, 16, 5)

	; return the key
	Return encrypted

End Function


write down the password... ;D
and then...

;must include the dashes!!!!!

username$=Input("Username: ")
loginnum$=Input("Password: ")

bob$=keygen$(username$)
Print bob
If loginnum$=bob$ Then Print "yay" Else Print "you suck"  


Function keygen$(name$)

	; change v$ to as many or few random or unrandom letters, numbers, characters whatever
	; this is what the key is going to be made out of
	; You can have duplicates all over the place if you want, it's up to you!
	; This is one part that will make your keys unique to other people using this program
	; e.g. v$="I1D9U0AJ5PFWIN1TR3EKLWZID42HU7KL8S6LTBN9VMCXOF6T46GY3JHIE9T7VTLFDEQ3Y38P"

	v$ = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"

	tname$ = name$

	; make name longer if necessary
	; again adjust this to make your keys unique

	namel = 20
	Repeat
		If Len(tname) <= namel
			temp$ = ""
			For n = 1 To Len(tname)
				temp = temp + Chr(Asc(Mid(tname, n, 1)) + 1)
			Next
			tname = tname + temp
		EndIf
	Until Len(tname) > namel

	; this bit makes sure that you don't get any obvious repetitions over the 20 character key
	For n = 5 To 100 Step 5
		If Len(tname) = n Then tname = tname + "~"
	Next

	; create encrypt string
	encrypt$ = ""
	For n = 0 To 19
		encrypt = encrypt + Chr(1)
	Next
	ee = 1

	; over load encrypt 30 times
	; change this to make your keys unique further

	For l = 1 To 30

		For n = 1 To Len(tname)
			a = Asc(Mid(tname, n, 1))
			a = a - 32

			temp$ = ""

			For nn = 1 To 20
				tl = Asc(Mid(encrypt, nn, 1))
				If nn = ee Then temp = temp + Chr(tl + a Mod 256)Else temp = temp + Chr(tl)
			Next
			encrypt = temp
			ee = ee + 1
			If ee = 20 Then ee = 1
		Next

	Next

	; suck out the key
	encrypted$ = ""
	For ee = 1 To 20
		e = Asc(Mid(encrypt, ee, 1))Mod Len(v)
		If e = 0 Then e = 1
		encrypted = encrypted + Mid(v, e, 1)
	Next

	; format the key with -'s
	encrypted = Mid(encrypted, 1, 5) + "-" + Mid(encrypted, 6, 5) + "-" + Mid(encrypted, 11, 5) + "-" + Mid(encrypted, 16, 5)

	; return the key
	Return encrypted

End Function



wizzlefish(Posted 2004) [#9]
thanks....