Lea Verou
03-03-2006, 04:31 AM
I'm developing a website for a client, it has nothing to do with vBulletin.
There is only one admin account in the system. (Users do not register)
Obviously I needed to make a system for her to login, and then keep her logged in while she browses the admincp and adds stuff to her website. I read that most php applications do this with sessions and cookies, but I did not have a knowledge on either of them, and I didn't like the fact that you can only call setcookie before sending any html. Also, sessions seemed too complicated for me to understand, and I have to finish the site until about 15th of March, so I can't waste any more time.
So, this is what I did:
When she installs the software, she enters her preffered admin username and password. These are stored in the database (btw should I encrypt the password? If so, why?). There are also 2 other entries in that db table, islogged and adminip. By default they are both set to 0. When she logs in, the script gets the correct username and password from the database, compares them with the submitted ones, and if they match it sets islogged to 1 and adminip to the computer's IP from which she logged in. In every page in the admincp I include (require() in fact) a small script that checks if islogged is 1 AND adminip matches the computer's ip. If not, it redirects the user to the login page by header(location: blah blah blah); . There is also a logout that sets islogged to 0 and adminip to 0. There is no timeout (but eventually the IP will change if it's not static) and the good thing (compared to cookies) is that it doesn't need a second login if you view the site with a different browser (as it doesn't depend on the browser's cookies).
My question is (and thank you for reading the whole thing! :o):
Since I haven't heard of this way for logins, there must be a reason for that. Does it pose a security risk? How can it be bypassed?
Thanks a lot in advance! :)
There is only one admin account in the system. (Users do not register)
Obviously I needed to make a system for her to login, and then keep her logged in while she browses the admincp and adds stuff to her website. I read that most php applications do this with sessions and cookies, but I did not have a knowledge on either of them, and I didn't like the fact that you can only call setcookie before sending any html. Also, sessions seemed too complicated for me to understand, and I have to finish the site until about 15th of March, so I can't waste any more time.
So, this is what I did:
When she installs the software, she enters her preffered admin username and password. These are stored in the database (btw should I encrypt the password? If so, why?). There are also 2 other entries in that db table, islogged and adminip. By default they are both set to 0. When she logs in, the script gets the correct username and password from the database, compares them with the submitted ones, and if they match it sets islogged to 1 and adminip to the computer's IP from which she logged in. In every page in the admincp I include (require() in fact) a small script that checks if islogged is 1 AND adminip matches the computer's ip. If not, it redirects the user to the login page by header(location: blah blah blah); . There is also a logout that sets islogged to 0 and adminip to 0. There is no timeout (but eventually the IP will change if it's not static) and the good thing (compared to cookies) is that it doesn't need a second login if you view the site with a different browser (as it doesn't depend on the browser's cookies).
My question is (and thank you for reading the whole thing! :o):
Since I haven't heard of this way for logins, there must be a reason for that. Does it pose a security risk? How can it be bypassed?
Thanks a lot in advance! :)