How do I secure a login?

Get help using Construct 2

Post » Tue Feb 24, 2015 5:34 pm

My game uses savedata that is saved on a database which I host. The saves are chosen with a key using the players username. The player can log in and play the game with their save. I want the system to be as secure as possible. I authenticate the user by giving them a unique token every time they log in and storing it in webstorage as a session value; then when an AJAX request is sent it includes the username and token which can then be authenticated. This stops me dealing with the password more than once. I have a logout function which updates the token on the server to a value which will automatically fail authentication so the account is inaccessible without the password input again.

Given this scenario, how can I make it secure?

A user is playing the game, and instead of pressing logout, they just close the tab the game is running in, and so the logout command is never executed. The server still has the token stored and has not been set to the lock value. Somebody could exploit that the token is stored in the browser, and since the server hasn't changed the token, retrieve the token and use it to act against the account.

Would storing the token as a global variable solve this? If not, what can I do?

Is setting the lock value on logout even needed? The token each user has is 64 characters long from a set of 62 characters, giving 5.16497385e+114 possible combinations of token, I feel this could be bruteforced which is why I added the logout lock.
Nothing goes unanswered!
B
22
S
5
G
1
Posts: 430
Reputation: 3,388

Post » Tue Feb 24, 2015 6:25 pm

some thoughts:
Store the IP of the user, you can directly compare that.
You could use the IP in the token generation.
If you take that one step further, you can include the user browser agent ID in the token generation too.
You can use an auto timeout on the server.
Each time you request the user data and successfully authenticates, update a time stamp int he user table.
If you use tasks or cron jobs, you can have a script run at an interval to check timeouts in the user table based on the time stamp.
Use https connections for the ajax.
You could have a new token generated every request, or every X request, and have the client update theirs after having authenticated and a new one is generated.
Have the server generate the token each request instead of storing it in the db.
I found that using MD5()'ed (php) strings really usefull.
Just make a list of strings including all required information, then MD5 the whole string into an unique value/token.
Who dares wins
B
53
S
13
G
11
Posts: 1,758
Reputation: 13,830

Post » Tue Feb 24, 2015 8:12 pm

@lennaert Thanks for your response

1. How would I go about using https when I'm referencing the files relatively?

2. How would you get the users ip? Would $_SERVER['REMOTE_ADDR']; work in php, even if the file is being accessed by AJAX?

3. How do you get browser agent ID? (I don't want to have to rely on data send by the client)
Nothing goes unanswered!
B
22
S
5
G
1
Posts: 430
Reputation: 3,388

Post » Tue Feb 24, 2015 9:52 pm

1. Even if you refer to files relatively, the call is still being made over a http connection.
Just use the whole address, adding the https int he ajax call.

The ajax calls will be made by the client, and its info will be sent in the headers as if browsing.

2. As soon as you have an application running in a browser, and you perform ajax calls (to your php files for example), your making calls over the internet, https adds extra security.



3. 'HTTP_USER_AGENT'
PHP can get all the info, php.net server calls
Who dares wins
B
53
S
13
G
11
Posts: 1,758
Reputation: 13,830


Return to How do I....?

Who is online

Users browsing this forum: Kyatric, oddreal, oosyrag, waguilar and 2 guests