Hello, E*PVP community! I hopefully have a relatively useful PHP guide/release for you here today.
After all the PHP I've done with websites over the last couple of years, I've never really learned more than I have on the last project I had begun working on, which was a PHP, tick-based MMORPG (a tick-based MMORPG is a MMORPG that allows the user do do RPGish actions, but the server part of it is refreshed every time the user either loads the page, or every set time or so. For instance, the leaderboards might be set to update every 15 minutes).
One thing that really had me thinking about this, is how I handle registration and cookies. Cookies used wrong are very dangerous to a user's security. Here's some PHP code that basically says
And let's say a user's admin level was not 4, but maybe 1 being a basic member. Using a Cookie editor, they could easily change that number to 4, and get by the adminlevel check.
What I've come up with, while yes, it might be slightly inefficient since you could use Sessions instead, but in cases where you need to use Cookies, or you just want to be safe, I've come up with this:
When a user registers, it takes their username and password and Sha1 hashes them both.
Afterwards, it creates a "secretkey" variable that combines both of those new hashed values and creates a Sha512 hash out of it generating quite a long secret key and then stores it in the database.
Why this is useful is because when I write my PHP code, I force every page that let's a user perform some sort of action to check the secretkey and then see if the user's cookies match the value in the database. If it doesn't, it gives them a javascript alert and notifies me via email that they've changed their cookies.
You might be thinking "Okay, well they could change their secretkey too."
Well no, because since the secretkey is generated using algorithms, every key is unique. They'd have to know a user's username and password both and hash them in order to get the new values, and then hash both of those values to get the new value.
Some might say there's an easier way, but this way has worked for me, and if you need to use Cookies and don't have any security knowledge then this would definitely be a start.
EDIT:
Sorry this is a big wall of text, and over time I'll re-word my explanations and make this post more beautiful, but here it is for now. If you'd like the PHP file, it can be downloaded as an attachment.
- xSherufanir/xBlackPlagu3x; Please rate the helpfulness of this. ^^
After all the PHP I've done with websites over the last couple of years, I've never really learned more than I have on the last project I had begun working on, which was a PHP, tick-based MMORPG (a tick-based MMORPG is a MMORPG that allows the user do do RPGish actions, but the server part of it is refreshed every time the user either loads the page, or every set time or so. For instance, the leaderboards might be set to update every 15 minutes).
One thing that really had me thinking about this, is how I handle registration and cookies. Cookies used wrong are very dangerous to a user's security. Here's some PHP code that basically says
Code:
if ($COOKIE['adminlevel'] == 4)
{
// Execute code here
}
What I've come up with, while yes, it might be slightly inefficient since you could use Sessions instead, but in cases where you need to use Cookies, or you just want to be safe, I've come up with this:
When a user registers, it takes their username and password and Sha1 hashes them both.
Afterwards, it creates a "secretkey" variable that combines both of those new hashed values and creates a Sha512 hash out of it generating quite a long secret key and then stores it in the database.
Why this is useful is because when I write my PHP code, I force every page that let's a user perform some sort of action to check the secretkey and then see if the user's cookies match the value in the database. If it doesn't, it gives them a javascript alert and notifies me via email that they've changed their cookies.
You might be thinking "Okay, well they could change their secretkey too."
Well no, because since the secretkey is generated using algorithms, every key is unique. They'd have to know a user's username and password both and hash them in order to get the new values, and then hash both of those values to get the new value.
Some might say there's an easier way, but this way has worked for me, and if you need to use Cookies and don't have any security knowledge then this would definitely be a start.
EDIT:
Sorry this is a big wall of text, and over time I'll re-word my explanations and make this post more beautiful, but here it is for now. If you'd like the PHP file, it can be downloaded as an attachment.
- xSherufanir/xBlackPlagu3x; Please rate the helpfulness of this. ^^