Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple authorisation / login capability in php

I'm looking to implement user login onto my site for the first time. I'm happy to either build my own solution, or implement something open source, however no package has been an obvious choice in my search so far. Equally, I'm fully aware that as an intermediate php programmer at best, I am highly likely to miss something obvious if I roll my own solution, and leave the doors well and truly open.

Any suggestions? We're not talking super sensitive or payment data here, but equally, I'm keen not to have people mess up my site!

requirements are - php based - simple as possible, not need for fancy bells and whistles - not Zend framework, since i've now rolled my own very basic frameworkthanks to this post

Thanks for your input.

like image 744
Rob Y Avatar asked Jan 14 '09 17:01

Rob Y


People also ask

What is authorization and authentication in PHP?

This typically involves a simple username and password check. Thus, a user who is logged in is an authenticated user. Authorization, often called access control, is how you guard access to protected resources and determine whether a user is authorized to access a particular resource.

How do I set basic authentication in HTTP header PHP?

Once the user has filled in a username and a password, the URL containing the PHP script will be called again with the predefined variables PHP_AUTH_USER , PHP_AUTH_PW , and AUTH_TYPE set to the user name, password and authentication type respectively. These predefined variables are found in the $_SERVER array.


2 Answers

A few good security gotcha's are

  • never store the an un-encrypted users password in the database
  • never store the users password or even a hash of the password in session or cookie data.
  • If you need to have ensure that the login is secure you have to use https.

I found these article very helpful in building login systems with cookies:

  • blog post on the fishbowl.
  • Improved Persistent Login Cookie Best Practice
like image 85
Brian Fisher Avatar answered Oct 19 '22 17:10

Brian Fisher


"You'll put your eye out kid."

Security is hard. I hate to say this, but the odds of you making a simple authorization scheme that is secure are quite slim. There is no easy mode here. So you might want to start by reading through a bunch of authentication code in the various frameworks/cmses, and other places where you can see how others have done it, and begin researching.

Here are some links: http://www.topmost.se/personal/articles/casual-cryptography-for-web-developers.htm http://pear.php.net/packages.php?catpid=1

like image 28
jacobangel Avatar answered Oct 19 '22 19:10

jacobangel