Hi
I have been coding a login/registration system today. I don't want to the post the code here else someone might take my work that I have worked quite a while on, I'll try and explain what I have done![Smile :) :)](/styles/default/xenforo/vbSmilies/Normal/smile.gif)
On the index.php for now you will be able to see a table with all the usernames and password in it, this is just temporary for when it's not being used properly.
When you haven't got a cookie stored (we'll come to them later) on the page, below the table, you'll see:
register.php - a basic form, not security holes in that as it's just a form. This form submits to processreg.php.
At the top of processreg.php there is this:
And at the bottom is the else. This checks the username for HTML and goes to the else if there is HTML in the username, this will also be done for the password.
A bit below that I have:
This goes to the else if the username or password is blank or if the password wasn't repeated properly.
Now that the checking is done, if everything is all ok, it posts the info to SQL.
At the end of that it says register successful for now.
login.php - another simple form which goes to authenticate.php.
authenticate.php:
Here I have an SQL query, below I have this:
to check if that username/password actually exist in the database.
Under that if is "username or password incorrect" and then in the else is this:
These will be used on the index page.
index.php:
lets ignore the table for now, it's not meant to be there and won't be there if the register code is being used properly.
I set the cookie bits up:
Then I run an SQL query: select * from users where username='$cookie_username' and password='$cookie_password'
I then, below that used if(mysql_affected_rows()==0){ again to make sure the info in the cookie is valid, if it isn't the default "You are not logged in", "Register", and "Login" will be shown. If the information in the cookie is vaild then the register and login button will go away and you'll see "Logged in as <username>".
That's basically it, any security holes you can see in there please?
Any security things I have forgotten that I should have??
Thanks
Craig.
I have been coding a login/registration system today. I don't want to the post the code here else someone might take my work that I have worked quite a while on, I'll try and explain what I have done
![Smile :) :)](/styles/default/xenforo/vbSmilies/Normal/smile.gif)
On the index.php for now you will be able to see a table with all the usernames and password in it, this is just temporary for when it's not being used properly.
When you haven't got a cookie stored (we'll come to them later) on the page, below the table, you'll see:
Code:
You are not logged in.
Register
Login
register.php - a basic form, not security holes in that as it's just a form. This form submits to processreg.php.
At the top of processreg.php there is this:
Code:
if ($username === htmlspecialchars($username)) {
And at the bottom is the else. This checks the username for HTML and goes to the else if there is HTML in the username, this will also be done for the password.
A bit below that I have:
Code:
if (($username == "") || ($password == "") || ($password != $rpassword)) {
This goes to the else if the username or password is blank or if the password wasn't repeated properly.
Now that the checking is done, if everything is all ok, it posts the info to SQL.
At the end of that it says register successful for now.
login.php - another simple form which goes to authenticate.php.
authenticate.php:
Here I have an SQL query, below I have this:
Code:
if(mysql_affected_rows()==0){
to check if that username/password actually exist in the database.
Under that if is "username or password incorrect" and then in the else is this:
Code:
setcookie("PasswordCookie", $password, time() + 99999999);
setcookie("UsernameCookie", $username, time() + 99999999);
header("Location: index.php");
These will be used on the index page.
index.php:
lets ignore the table for now, it's not meant to be there and won't be there if the register code is being used properly.
I set the cookie bits up:
Code:
$cookie_username = $_COOKIE["UsernameCookie"];
$cookie_password = $_COOKIE["PasswordCookie"];
Then I run an SQL query: select * from users where username='$cookie_username' and password='$cookie_password'
I then, below that used if(mysql_affected_rows()==0){ again to make sure the info in the cookie is valid, if it isn't the default "You are not logged in", "Register", and "Login" will be shown. If the information in the cookie is vaild then the register and login button will go away and you'll see "Logged in as <username>".
That's basically it, any security holes you can see in there please?
Any security things I have forgotten that I should have??
Thanks
Craig.