random code generator
#1
Posted 20 June 2013 - 01:41 PM
Before a few days i played FTB and made something...
Now ... I wonder , is there any way to make random code generator (numbers+ ABCD... and with capitals)
That will save the code untill somone use that code and then delete that code?
1 computer will generate the code while redstone signal/the owner will tell it and 1
computer will recive that code and check if the input = to the code and then delete the code...
if its possible - can it have multiply codes & uses to the codes?
For example - I made map and i want that people will put diamond per code that have 10 uses or
Iron/coal per 1 enter... is that possible?
#2
Posted 20 June 2013 - 09:46 PM
#3
Posted 20 June 2013 - 11:05 PM
Having the server send a copy of a password to a client system is not exactly a secure way of doing things, if that's what you're aiming to do.
#4
Posted 20 June 2013 - 11:08 PM
#5
Posted 21 June 2013 - 02:28 AM
Nivm200, on 20 June 2013 - 01:41 PM, said:
That will save the code untill somone use that code and then delete that code?
1 computer will generate the code while redstone signal/the owner will tell it and 1
computer will recive that code and check if the input = to the code and then delete the code...
if its possible - can it have multiply codes & uses to the codes?
For example - I made map and i want that people will put diamond per code that have 10 uses or
Iron/coal per 1 enter... is that possible?
How I would do it...
Here is a good free random code generator, http://www.generater...ndom-codes-tool
Limited to 20K, but you can use prefixes and run it many times
- if that's not enough, then maybe use md5 with simple string and number increments ?:-/
Dump codes in mysql db using phpmyadmin
php script to receive ajax request, but need to make sure request comes from your own scripts, either with api key or some other way. HTTPS helps.
if the code is found, add code to "used_codes" table and delete from master_codes table.
If you want "10 uses" then keep another field "uses", increment each time. mysql can increment a field for you. Then only move to used codes table when it reaches 10
Issues I can see;
Validating source of request, only need this if you expect hack attempts.
Catering for Errors, eg. if you send "success" response. Did the app actually received and used that response. Probably want another ping back to server to say, received success.
Hard to suggest any more based on your post.
Hope that helps
#6
Posted 21 June 2013 - 02:37 AM
ChrisAustralia, on 21 June 2013 - 02:28 AM, said:
Simplest method...
— Create a table, or load a table from a file, that contains a list of all the currently used strings and their number of uses remaining
— Generate a random string, from something like a validChars list, making sure the string doesn't appear in the table of used strings
local validChars = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
— Store the random string into a table with the number of uses
— Save the uses table into a file for restart persistence
— Present the random string to a user
— When the string is used, check the table of uses, if it has 0 uses, return a failure back, when it has uses, decrement the uses and return success
#7
Posted 21 June 2013 - 05:13 AM
local table = {"1","2","3","4",}
for i = 1,"how long you want you're password" do
A = table[math.random(tonumber(#table))]
print(A)
end
#8
Posted 21 June 2013 - 05:22 AM
MR_nesquick, on 21 June 2013 - 05:13 AM, said:
local table = {"1","2","3","4",}
for i = 1,"how long you want you're password" do
A = table[math.random(tonumber(#table))]
print(A)
endThis would be the method I would use.
--# a table to store all the used codes, and their uses
local usedCodes = {}
--# all the valid characters that can be used
local validChars = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
local function generateCode(length, uses)
--# make sure only this function can access it
local code
--# repeat until a code that hasn't been used is found
repeat
--# start with an empty string
code = ""
--# loop for the desired length
for i = 1, length do
--# pick a random index for the character in the validChars string
local idx = math.random(#validChars)
--# append the randomly chosen character
code = code..validChars:sub(idx,idx)
end
--# when it has not been used, finish, else try again
until not usedCodes[code]
--# add the max uses into the table, if `uses` isn't provided assume 1
usedCodes[code] = uses or 1
--# return the resulting code
return code
end
Edited by theoriginalbit, 21 June 2013 - 05:25 AM.
#9
Posted 21 June 2013 - 05:54 AM
theoriginalbit, on 21 June 2013 - 05:22 AM, said:
MR_nesquick, on 21 June 2013 - 05:13 AM, said:
local table = {"1","2","3","4",}
for i = 1,"how long you want you're password" do
A = table[math.random(tonumber(#table))]
print(A)
endit was more a example how to select a random number or letter from a table. and tonumber(#table) is used to check how long the table is, so you can expand the table in the future without changing you're code
#10
Posted 21 June 2013 - 06:05 AM
#11
Posted 21 June 2013 - 06:07 AM
MR_nesquick, on 21 June 2013 - 05:54 AM, said:
MR_nesquick, on 21 June 2013 - 05:54 AM, said:
EDIT: Oh ninja's, GopherAtl you're good at ninja'in me lately!
#12
Posted 21 June 2013 - 06:12 AM
#13
Posted 21 June 2013 - 06:29 AM
If you'd like I could send it to you and you could see if it's helpful..
And as those above me as stated it isn't to hard to generate a random password..
Here's an example with just numbers
--Here's what can be in the password
numbers = {
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
}
--And let's save that into a file called "Password" and the password lenght will be 10
file = fs.open("Password","w")
for i = 1,10 do
n = numbers[math.random(1, #numbers)]
file.write(n)
end
file.close()
Typed this on my phone so I'm not 100% it works..
But I'm pretty sure it does
#14
Posted 27 June 2013 - 10:50 PM
Have you found a solution yet? Please share with us.
Cheers - Chris
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











