767 posts
Posted 09 May 2013 - 04:36 AM
Hello.
i'm trying to make a webpage, which has a 128 bit long string. but every X seconds that string, has to change, (the first string may never appear again, if used)
like a random string generator
but im quite lost, finding out, how..
btw. im using this to my AdvLock, program, ( new update )
Thanks in Advance :D/>
144 posts
Location
Wellington, New Zealand
Posted 09 May 2013 - 05:51 AM
This might help. It's pretty easy to use! :3
767 posts
Posted 09 May 2013 - 06:20 AM
ehhm.. how do i make it myself?
im making a website which displays a random 64 bit hexadecimal, and then changes that whole 64 bit string into another random… but the strings may NEVER appear again, if used before.
but what i wanted is just an example on how to do it with my own website…
But thanks :D/>
Any help, please?
7508 posts
Location
Australia
Posted 09 May 2013 - 08:27 AM
You know that this is a forum for ComputerCraft, which is Lua, right?
799 posts
Location
Land of Meh
Posted 09 May 2013 - 08:49 AM
I'll answer this even though this isn't CC related:
Simplest way is to use PHP and hash a random number (using SHA-1, because that will generate a hexadecimal string 128 bits long - 16 characters). Also, if this string is requested from within CC, it's probably easier just to change it each time the page is loaded, unless you want to write something that remembers the current string, and will change it if it's been longer than X seconds. PHP to generate the random string:
echo hash("sha1", rand(0, 2147483647));
2147483647 is the largest possible integer in PHP for a 32 bit system.
767 posts
Posted 09 May 2013 - 09:09 AM
well that doesnt show me anything, when testing..
btw. how do i then get the random string, to the computer.. (the computer reads the whole code for the website, and cant see the random string?)
EDIT: nevermind.. forgot to add <?php
EDIT2: nevermind about the "btw how do i …"
767 posts
Posted 09 May 2013 - 09:35 AM
You know that this is a forum for ComputerCraft, which is Lua, right?
Yes.. but this IS computercraft related.. i want to use it in my program..
But.. now i've seen that this: doesnt work properly.. i want it to delete everything from the table from the website, and only store the 128 bit string..
as i said.. this doesnt work:
x = http.get("http://advlock.webuda.com/index.php")
red = tostring(x.readAll())
print(red)
for k,v in string.gmatch(red, "(%w+)<header>(%w+)") do
print(k,v)
sleep(1)
end
EDIT: ehm, btw.. the random hexadecimal generator.. would that at anytime be equal to an existing hexadecimal?
like would the generator at some point generate the same password, two times?
8543 posts
Posted 09 May 2013 - 05:04 PM
Moved to General.
1522 posts
Location
The Netherlands
Posted 09 May 2013 - 05:35 PM
I would use something like this, however, I cant seem to get the array_search to get working properly :S
Im kind of new to PHP and this is just something I scrapped together. I hoped I at least pushed you in the right direction :)/>
Spoiler
<!--?php IP.board messing with me here
//#some action
$pw = array();
function generatePW()
{
$bool = false;
while(true)
{
$random = rand( 0, 2147483647 );
if( array_search(hash('sha1', $random), $pw, true) )
{
$bool = true;
}
if(!$bool) // Should trigger if bool is false, not a pro here ;)/>
{
//Add to the array, not sure how to do that
return hash('sha1', $random);
}
}
}
?>
1583 posts
Location
Germany
Posted 09 May 2013 - 05:43 PM
You know that this is a forum for ComputerCraft, which is Lua, right?
Yes.. but this IS computercraft related.. i want to use it in my program..
But.. now i've seen that this: doesnt work properly.. i want it to delete everything from the table from the website, and only store the 128 bit string..
as i said.. this doesnt work:
x = http.get("http://advlock.webuda.com/index.php")
red = tostring(x.readAll())
print(red)
for k,v in string.gmatch(red, "(%w+)<header>(%w+)") do
print(k,v)
sleep(1)
end
EDIT: ehm, btw.. the random hexadecimal generator.. would that at anytime be equal to an existing hexadecimal?
like would the generator at some point generate the same password, two times?
In the output (the source you can see in a webbrowser) of an php script isn't a tag unless you printed it out. So, your program can't find the head tag :)/>
767 posts
Posted 09 May 2013 - 06:32 PM
Well Thanks.. everything works now.. :D/> but i have a new question:
in my program, then it
http.get("randomGenerator name")
. but.. then i want the cc terminal to:
http.post("website, with mysql database")
so the serial key(the random string) would be store inside that mysql database.
how do i then make a new website, which saves the serial key, sended and thenstore it to the db?
Thanks
1243 posts
Location
Indiana, United States
Posted 11 May 2013 - 07:54 AM
If I understand your second question correctly, the answer is Google + basic comprehension skills.
182 posts
Posted 13 May 2013 - 07:52 AM
Use the PHP $_POST to get data from the request but use http.request not http.post or http.get
799 posts
Location
Land of Meh
Posted 13 May 2013 - 07:57 AM
Use the PHP $_POST to get data from the request but use http.request not http.post or http.get
http.post and http.get just wrap the http.request function (they call it). It'll make no difference (apart from the way the data is returned) calling http.request over http.post or http.get.