Hey guys,
I'm currently working on an online high score system using Panther, php and a MySQL table.
Panther sends off a page request that contains all the information like so:
(contents of file at URL:[(page link) [.php?username=](username)[&password=](password)[&score=](score))
so that the webpage can then read that out and use the $_GET command to pull the information from the URL and process it.
I have two problems that I need help with. Firstly, How can I compare the username to a table of registered users to see if they are registered and set the result to a variable? (I need to compare the password too)
Secondly, This seems a slightly unsafe way of doing it. There's nothing stopping someone from realising that the score is in the URL and sending off a very high score to the page. Can anyone think of a safer method of sending the information? Thanks!
Offline
I don't know much about Squeak / Smalltalk and the libraries that are available, but is there one that can directly access a SQL database? Like in Java there is the JDBC where you can directly run SQL commands without the need of using PHP files. This seems a safer method as a person couldn't intervene. And for checking the username/password (if still using PHP) you could compare the what you need and then 'echo' out the results and just have Panther read the output stream (ie. echo '0' if they're both correct or '1' if one of them is not the same).
Offline
PHP code:
<?php
$con = mysql_connect("dbhostname","username","password");
mysql_select_db("highscore",$con);
$loggedin=("SELECT PASSWORD FROM users_and_passwords WHERE username = '" . $_GET["username"] . "'" == $_GET["password"]);
if($loggedin){
//code to add highscore to database
echo("highscore added");
}
else
{
echo("incorrect username/password");
}
?>
Something like that should work. If you want security, I would use posts rather than gets, but Panther doesn't support them.
Offline
wcfs96 wrote:
Got it to work
Now to transfer to Scratch (might be a challenge because of dependency issues :\)
I don't think dependency issues are a problem. If you're able to get it into Panther, then it will work (theoretically). The problem is, it won't be in everyone's copy of Panther, so it would be hard to distribute the project.
Offline
ScratchReallyROCKS wrote:
wcfs96 wrote:
Got it to work
Now to transfer to Scratch (might be a challenge because of dependency issues :\)
I don't think dependency issues are a problem. If you're able to get it into Panther, then it will work (theoretically). The problem is, it won't be in everyone's copy of Panther, so it would be hard to distribute the project.
Actually I am running into dependency issues (Scratch really takes a lot out from Squeak) The Mysql library would be in the .image so within an update everyone should have it. I'm wondering if I could put Scratch onto the newest version of Squeak and keep all the core libraries so it would be much easier to add things to it. I'll try it on Panther as well but I'm sure I'll run into the same problems I was having with Scratch.
Offline
Taneb wrote:
PHP code:
<?php
$con = mysql_connect("dbhostname","username","password");
mysql_select_db("highscore",$con);
$loggedin=("SELECT PASSWORD FROM users_and_passwords WHERE username = '" . $_GET["username"] . "'" == $_GET["password"]);
if($loggedin){
//code to add highscore to database
echo("highscore added");
}
else
{
echo("incorrect username/password");
}
?>
That has a HUGE security flaw. I used a similar script for my website once, and I found it wasn't secure in the slightest.
What you do is just provide a non-existant username with no password and it will let you in. Because there is no entry in the table with the provided username from which to select the password, when you try to access the password variable it will be blank. When compared to the empty password provided, it matches and logs you in.
A better script is as follows:
<?php
$con = mysql_connect("dbhostname","username","password");
mysql_select_db("highscores",$con);
$user = mysql_real_escape_string($_GET["username"]);
$pass = mysql_real_escape_string($_GET["password"]);
$result = mysql_query("SELECT password FROM users_and_passwords WHERE username = '" . $user . "' AND password = '" . $pass . "'");
if(mysql_num_rows($result) == 1){
//code to add highscore to database
echo("highscore added");
}
else
{
echo("incorrect username/password");
}
?>Last edited by TheSuccessor (2011-03-26 06:16:31)
Offline
Not sure if I can do this, the differences between the two is just too great, can't get anything to work. Do you know that version of Squeak Scratch is running? Also could you post a link to the Panther thread so I could download it.
Offline
sparks wrote:
From what I can tell then, sending the info in the "GET link" is the only method. It shouldn't be too unsafe as the link is only sent quickly to that one place, it shouldn't be too insecure.
I'm determined to get this to work
I'm on their IRC right now trying to figure it out, I think I know what I have to do now to get it to work.
Offline
sparks wrote:
From what I can tell then, sending the info in the "GET link" is the only method. It shouldn't be too unsafe as the link is only sent quickly to that one place, it shouldn't be too insecure.
It is definitely possible to get POST to work with Squeak. Look at the upload dialog source for Scratch projects. It is definitely using HTTP POST. We only have to adjust it...
Offline
hmm, you have a point. How does the page read it though? If the information isn't being sent in the link, where is it put?
Also, you know when you import a sound into scratch, it says down-sampling and converting to mono? What's with that? Can I get rid of it and keep high quality stereo sound or is it physically not possible for squeak to play stereo sound?
Offline
sparks wrote:
hmm, you have a point. How does the page read it though? If the information isn't being sent in the link, where is it put?
Also, you know when you import a sound into scratch, it says down-sampling and converting to mono? What's with that? Can I get rid of it and keep high quality stereo sound or is it physically not possible for squeak to play stereo sound?
Possibly.
It might be Squeak's problem, or maybe the Scratch Developers implemented it so the project size wouldn't be too impossible when sound was added.
Offline