It is currently Mon Sep 06, 2010 6:29 am




Post new topic Reply to topic  [ 10 posts ] 
Simple login system 
Author Message
Site Admin
User avatar

Joined: Sat Nov 22, 2008 3:41 pm
Posts: 512
Post Simple login system
Well joey wanted a login system for the website i made for him so i quickly made one.. So here's the code :).

It relies on the client having the same ip as the cookie it has (Securing the website from cookies thieves...)

The security.php
Code:
$password = "your password here";



$ip = $_SERVER["REMOTE_ADDR"];
$pass = $_POST[password];
if ($pass == $password){
setcookie("japie is a tool", $ip , time()+3600);
echo 'Access Granted, Redirecting to Japies resume in 5 seconds <META HTTP-EQUIV="Refresh"
      CONTENT="5; URL=index.php"><br>';
} else if ($pass == ""){
echo "";
}
else if ($pass != $password){
echo "<br>Invalid Password!<br>";
}




$cookie = $_COOKIE["japie is a tool"];

if ($ip == $cookie ){


} else {


}
$submit ='<form  action="security.php" method="post">
Password: <input name="password" type="password" id="password" size="40" maxlength="40" />
<input type="submit" value="Submit" name="submit" />';


if ($ip == $cookie ){
echo 'You are Already logged in and dont need to login again!<br>Redirecting to Japies Resume in 5 seconds..
<META HTTP-EQUIV="Refresh"
      CONTENT="5; URL=index.php">';

} else if ($ip != $cookie ){
echo $submit;
}
echo '<br><br><br> Security Page Coded by Matthew Vlietstra';
?>


And the index.php or other files you wish to secure (just add the heading).
Code:
<?
$ip = $_SERVER["REMOTE_ADDR"];


$cookie = $_COOKIE["japie is a tool"];

if ($ip != $cookie ){
echo '<META HTTP-EQUIV="Refresh"
      CONTENT="1; URL=security.php">';
die;

}


Note I made this pretty quickly so if you do see any flaws please point them out.. however Im pretty sure there aren't...

_________________
http://slightly-broken.com has a total of 569040 download links, from 12 different websites the pie graph bellow, compares the amount of unmetered downloads these websites have.
Image


Mon Apr 06, 2009 6:01 pm
Profile
1337

Joined: Fri Feb 20, 2009 9:42 pm
Posts: 147
Location: Kalgoorlie
Post Re: Simple login system
Quote:
Code:
$cookie = $_COOKIE["japie is a tool is a tool"];


:lol: :lol:

_________________
Ghostrider_2020
Coolermaster Storm Scout, AMD Athlon II X2 6000+ 3.1GHz, Asus M3N-HD HDMI, 4GB DDR2 800Mhz, Asus nVidia 9800 GT 1GB GDDR3, 1x Samsung HD501HJ 500GB SATA II, 1x WD EAVS 1TB SATA II, 2x WD EADS 1.5TB SATA II, 1x WD 400GB IDE, Total 4.9TB =]. LG DVD Burner, LG W2252 22" LCD, Acer 15" LCD, ThermalTake EVO_Blue 650W PSU, Logitech G9x, Logitech G15, 2x 120mm Delta 252CFM Fans, 1x 140mm Xigmatek Orange Fan, 2x UV Neons, 4x 3mm UV LEDs.
<Custom Built>


Wed Apr 15, 2009 10:52 am
Profile
ghay

Joined: Fri Jul 24, 2009 10:47 pm
Posts: 4
Post Re: Simple login system
One of the major issues with what you've done is that the password is being stored in plain text, which becomes really nasty if someone manages to {a} find an SQL injection vulnerability that allows them to dump the users table (thus giving them every user's password - how many sites do you use the same username/password combo on?), {b} manage to get their hands on a backup SQL dump, or {c} manage to break into the SQL server itself*.

The passwords need to be encrypted one-way (or hashed) before they are stored so that if your user data is exposed, you will keep them at least partially safe. The problem with this is that the most common and easy hash system (MD5) has large, searchable rainbow tables on the internet, making finding the original password from the hash much easier.

To stop THIS happening, you need to salt the passwords before you hash them.

By salt, I mean add a set of characters that are only known to the website owner to the password before hashing and storing it. This makes the password longer and more complex, making even easy passwords difficult to find.

Essentially, you need to have something like this:

Code:
$salt = "C*CEGYIEW(*#$QRQR)*!#R#*R@`12345678+_)(*&^%$#@!].;Y(RE";
$password = "your pre-salted, hashed password here";

$pass = md5($salt . $_POST[password] . $salt)

if ($pass == $password){
setcookie("japie is a tool is a tool", $ip , time()+3600);
...



With a salt that long, and applying it twice, it doesn't really matter if other people find out what it is, because it will never show up on the rainbow tables in a million years.


*This is assuming, of course, that you will eventually want a multi-user system, or want to store the p/w in a database to make it easier to change. Of course, if your web server or php interpreter coughs, you could be presented with the php code instead of it being parsed, giving you the same kind of password theft issues. Never leave passwords in plain text ;)


Fri Jul 24, 2009 11:07 pm
Profile
Site Admin
User avatar

Joined: Sat Nov 22, 2008 3:41 pm
Posts: 512
Post Re: Simple login system
Firstly for this system i wan't using a database.
So
A) users won't be able to use sql injection to acquire username's + passwords because the passwords stored in the php file. Therefore no sql dumps.
B) I tried to use different passwords for all the sites i register on as well as changing my email password regularly - i am fully aware of password management.
C) i am fully aware of encryption methods, md5. I was going to encrypted the cookie that this script outputted but laziness overcame me, i am also familiar with salting passwords and have done this multiple times for websites I've created.

*I created this script in like 5-10mins for a friends temp resume website... It didn't really require too much more coding.. this was sufficient.. but ya i suppose i should have implement more security, which i normally do for db based websites.

Anyways nuff of me defending my code :)
Do you reside in Kalgoorlie? or are you someone who stumbled upon this forum?

_________________
http://slightly-broken.com has a total of 569040 download links, from 12 different websites the pie graph bellow, compares the amount of unmetered downloads these websites have.
Image


Sat Jul 25, 2009 4:18 pm
Profile
ghay

Joined: Fri Jul 24, 2009 10:47 pm
Posts: 4
Post Re: Simple login system
No, I'm from Esperance - I was pointed here by a member from Norseman.


Sat Jul 25, 2009 8:48 pm
Profile
Site Admin
User avatar

Joined: Sat Nov 22, 2008 3:41 pm
Posts: 512
Post Re: Simple login system
Quote:
No, I'm from Esperance - I was pointed here by a member from Norseman.

Ah ic.
Well welcome to Kalgaming...

Sorry that I'm being so rude...
Well anyways so like how long have you been doing PHP/ web design? and like what websites have to created/ managed?

_________________
http://slightly-broken.com has a total of 569040 download links, from 12 different websites the pie graph bellow, compares the amount of unmetered downloads these websites have.
Image


Sat Jul 25, 2009 8:56 pm
Profile
ghay

Joined: Fri Jul 24, 2009 10:47 pm
Posts: 4
Post Re: Simple login system
I don't do much in the design, I generally make the design a page, and do the backend coding - most of the stuff is on school intranets.

I've owned/managed/run highly customised phpBB boards, provided live support for phpBB online (IRC), and I've been programming since year before I was in year 5. I've been doing web design for 10 years, and php for 6 years, but I have coded in:

  • BASIC/qBASIC/Apple BASIC/Visual BASIC
  • Delphi
  • C/C++/C#
  • Java
  • Python
  • Javascript
  • PHP
  • mIRC Script
  • VBScript (asp)
  • Bash/DOS and various other scripting languages
...and I've developed databases in Access and mySQL.

And I have a big thing about security and plaintext passwords ;)


Mon Jul 27, 2009 7:02 pm
Profile
Site Admin
User avatar

Joined: Sat Nov 22, 2008 3:41 pm
Posts: 512
Post Re: Simple login system
Magilla wrote:
I don't do much in the design, I generally make the design a page, and do the backend coding - most of the stuff is on school intranets.

I've owned/managed/run highly customised phpBB boards, provided live support for phpBB online (IRC), and I've been programming since year before I was in year 5. I've been doing web design for 10 years, and php for 6 years, but I have coded in:

  • BASIC/qBASIC/Apple BASIC/Visual BASIC
  • Delphi
  • C/C++/C#
  • Java
  • Python
  • Javascript
  • PHP
  • mIRC Script
  • VBScript (asp)
  • Bash/DOS and various other scripting languages
...and I've developed databases in Access and mySQL.

And I have a big thing about security and plaintext passwords ;)



Very very nice.. hehe's I've only been doing PHP for like less then a year, and html for a little more.. but ya im kind of lazy, so don't do too much...

Ya fair enough.. hehe's well ya like i don't mind if it's in php at least no on can see it.. unless i gain access to ur server or something... but ya i always secure passwords in a DB as well as securing all fields... because of SQL injection and all that..
my latest creation -> http://bargainboard.kalgaming.net
well one of them.. still has heaps of work to do.

_________________
http://slightly-broken.com has a total of 569040 download links, from 12 different websites the pie graph bellow, compares the amount of unmetered downloads these websites have.
Image


Mon Jul 27, 2009 7:58 pm
Profile
ghay

Joined: Fri Jul 24, 2009 10:47 pm
Posts: 4
Post Re: Simple login system
If the php processor burps, it will spit out the entire php code in plain text, including any and all variables.

just so you know ;)

Edit: any reason that you're using cookies rather than php sessions?


Mon Jul 27, 2009 9:17 pm
Profile
Site Admin
User avatar

Joined: Sat Nov 22, 2008 3:41 pm
Posts: 512
Post Re: Simple login system
it does? lol... ok well then.. that's something i haven't heard of..
ya i never really went into using sessions (haven't tried but heard of)...

_________________
http://slightly-broken.com has a total of 569040 download links, from 12 different websites the pie graph bellow, compares the amount of unmetered downloads these websites have.
Image


Mon Jul 27, 2009 9:25 pm
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 


Who is online

Users browsing this forum: odettegree and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.