I will try to make this as short as possible and as simple as possible. I used to develop websites in the past. So i know that when you login in the websites, your client gets cookies, sessionid and so on…
But i don’t know how this stuff works in unity. So, after following a tutorial, and reading some info about unity, i made the following.(Using prepared statements)
CLIENT:
-User logs into the game, his inputs are username, password.
SERVER:
-Checking if the username has special characters
-Checking if the username matches the input’s character length requrements
-Checking if the username exists in the database
-Checking if the password matches the hash from the database
-Generating session key made out of random numbers, current datetime in numbers, more random numbers and his username shuffled
-Sending back to the client the session key and return successful login.
So when the server sends the key to my unity application, the application doesnt do something special with that key but simply storing it into a static variable that will be accessible in all scenes. Each time the user performs something in the game that would select,insert,change a database value, his client will send his username and key, and the server will check if his client key matches the database key.
If the server was checking only his username… for example…
CLIENT:
-The user equips an item
SERVER:
- SELECT * FROM players WHERE username = (the client’s sended username);
If the server was checking only his username, then the player could edit that username using hacks and then play trough someone else’s account. Which is why i made this key to make it work the following way.
CLIENT:
-The user equips an item
SERVER:
- SELECT * FROM players WHERE username = (the client’s sended username) AND sessionkey = (the client’s sended sessionkey);
-Check if that client’s username & key are matching the ones from the database, if not, disconnect the user.
So in order for the hacker to go into someone else’s account, he will also need the key of that someone else’s account. This key is unique, and new key is generated for the user’s account after each login. It is made out of over 20 characters, so no hacker could guess what the user’s key is. I made this to prevent account swap … i don’t know how to even call this but i hope you guys understand.
The problem here is that i asked 2 of my programmer friends, they said that what i’m doing is retarded. (Combining C# and PHP). Why there are tutorials for this then…? Is what i’m doing above amateur? Is there a better way to do this login system? Please help me, because i don’t want to continue making this game, and then rework everything just because i realized that i’ve done it in a wrong way. Thank you for your time.