Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Java Game Launcher/Downloader - User Authentication


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 keywi   Members   -  Reputation: 115

Like
0Likes
Like

Posted 15 January 2014 - 08:49 AM

Hi there,

I'm trying to make a game launcher in Java that will request a username and password, post the data to a website, let the website check its database for a match and then let the user receive/update the game depending on whether it is a success or not.

I've been looking deeper into PHP, MySQL, TLS/SSL and Apache, but I am still not sure how to set this up correctly. I'd like good security as well which makes it a tad more difficult.

I have been searching like crazy but I still have some unanswered questions:

1. How can I establish a secure connection from a client-side Java program to a server-side PHP/MySQL structure? Any libraries/packages?

2. How is the data sent from the client interpreted server-side? Is it by extending an URL with the data like "https://127.0.0.1/login.php?data=stuff&method=login"?

Any tips or hints on what I should look at would be greatly appreciated!

Thanks for reading my wall of text!

Sponsor:

#2 hplus0603   Moderators   -  Reputation: 5547

Like
1Likes
Like

Posted 15 January 2014 - 03:39 PM

Simply use a SSL (or HTTPS) library on the Java side. Configure Apache (or Nginx, or whatever your PHP host is) to run HTTPS with a certificate. If you use self-signed certificates, install the public certificate on the client machine and load that for the SSL library.
 
Then formulate a HTTPS POST with the data in whatever format you want -- JSON, XML or x-www-form-urlencoded are common formats. Send it to the server. Wait for the reply.
 
On the server, in PHP, you read the input like so:
 

$contents = file_get_contents("php:" . "//input"); // split the string because gamedev.net

"php input" is a string that I for some reason can't post as-is into the forum software (!)

 

The input comes from the POST or PUT request to the URL from the request body.

 

And parse it (if it's JSON) like so:

$variables = json_decode($contents)

Typically, you store the user name, and the bcrypt() of the password salted with the username, in a database table. You can then check for proper login by simply doing a select where username=(thename) and bcrypt_password=bcrypt(thepassword + thename). This avoids storing the password in an easily recoverable format in the database, so if the database somehow leaks to the greater internet, the plaintext passwords are not revealed.
 
Also, do not put user arguments into strings for database queries; use a database API that allows you to use symbolic query parameters so there is no risk of SQL injection.


Edited by hplus0603, 15 January 2014 - 06:38 PM.

enum Bool { True, False, FileNotFound };

#3 keywi   Members   -  Reputation: 115

Like
0Likes
Like

Posted 15 January 2014 - 04:58 PM

It looks like I'll be using Apache and I'll look into finding a good Java library for SSL. After reading up a bit on certificates I guess it makes sense for me to use a self-signed certificate for now as it's not a website that will be displayed.

 

I'm familiar with JSON so that shouldn't be a problem.

 

Thanks for the security tips. I figured I'd have to encrypt the data, and shield the database from SQL injections, but now I know what API to look for.

 

How would I read the input in PHP? I think you missed filling in the field by accident.

 

EDIT: My guess would be something like 

$contents = $_GET["data"];

Edited by keywi, 15 January 2014 - 05:02 PM.


#4 hplus0603   Moderators   -  Reputation: 5547

Like
1Likes
Like

Posted 15 January 2014 - 06:40 PM

No, the input is the post / put request body, and is parsed from php input (the URL which I cannot post straight in this forum !)

 

A HTTP request has a URL, which may have a query string, some headers, and a body.

 

PHP will attempt to decode the query string, and provide the values of that query string in $_GET.

PHP will also attempt to decode the request body if it is in the format x-www-form-urlencoded (which looks like a query string) and provide the values of that decode in $_POST. However, it will not decode JSON or XML formatted request bodies, so you have to do that yourself.


enum Bool { True, False, FileNotFound };

#5 keywi   Members   -  Reputation: 115

Like
0Likes
Like

Posted 16 January 2014 - 06:03 AM

OK, everything you say makes sense. I was stuck in the mindset that input had to be processed as part of a query string.

Would you recommend any particular software to run a locally hosted version on a Windows machine? I'm currently using xampp (it's working fine so far) and I tried using a Ubuntu virtual machine on Amazon EC2, but it feels very impractical in these early stages. I definitely think EC2 is the way to go though when it's ready for launch.

The reason I'm asking is that it would be practical for me to use a local setup that is almost identical to an EC2 setup. The easier it is for me to upload my files and get it running the better. I guess my real question is if there's anything I should look out for? Like versions of PHP or anything else that could differ between a live and local version.

#6 hplus0603   Moderators   -  Reputation: 5547

Like
1Likes
Like

Posted 16 January 2014 - 10:18 AM

Would you recommend any particular software to run a locally hosted version on a Windows machine?


At work, we use VMWare Workstation, running one (or a few) Ubuntu images that look a lot like our production hardware. This is great, and lets developers use Macs, Windowses, or raw Ubuntu for development. Workstation costs money, though. There are alternative VM hosts that are free if this is an issue for you.

Another option is to use a server technology that has both Windows and Linux support. Apache/PHP on Windows is troublesome, but can be made to work. node.js works on both Windows and Linux. Python works on both Windows and Linux, and you can use the "simple" self-hosted version for development, and use a WSGI server in production.
enum Bool { True, False, FileNotFound };

#7 keywi   Members   -  Reputation: 115

Like
0Likes
Like

Posted 17 January 2014 - 03:43 AM

I think I'm starting to get a hang of it. Managed to make a request with a username and password in the HTTP request body, receive the data in PHP, look for a match in the database and send back a simple header response. I need to do some research on setting up SSL. I'm not entirely sure what software to use to make self-signed private and public keys. I used the keytool in the jre7/bin folder to make one, but I don't know how to make a private one for the server. I'm pretty sure I need to specify its settings in the server.xml file, but its just the creation and storage of keys that's got me a bit stumped.

Thanks for all the help you've given me thus far!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS