13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

408 Chapter 17 Implementing Authentication with <strong>PHP</strong> <strong>and</strong> <strong>MySQL</strong><br />

We included the directive Auth_<strong>MySQL</strong>_Encryption_Types to specify that we want to<br />

use <strong>MySQL</strong> password encryption. Acceptable values are Plaintext, Crypt_DES,or<br />

<strong>MySQL</strong>. Crypt_DES is the default <strong>and</strong> uses st<strong>and</strong>ard Unix DES-encrypted passwords.<br />

From the user perspective, this mod_auth_mysql example will work in exactly the<br />

same way as the mod_auth example. She will be presented with a dialog box by her web<br />

browser. If she successfully authenticates, she will be shown the content. If she fails, she<br />

will be given the error page.<br />

For many websites, mod_auth_mysql is ideal. It is fast <strong>and</strong> relatively easy to implement,<br />

<strong>and</strong> it allows you to use any convenient mechanism to add database entries for<br />

new users. For more flexibility <strong>and</strong> the ability to apply fine-grained control to parts of<br />

pages, you might want to implement your own authentication using <strong>PHP</strong> <strong>and</strong> <strong>MySQL</strong>.<br />

Creating Your Own Custom Authentication<br />

In this chapter, you looked at creating your own authentication methods including some<br />

flaws <strong>and</strong> compromises <strong>and</strong> using built-in authentication methods, which are less flexible<br />

than writing your own code. Later in the book, after you learn about session control,<br />

you will be able to write your own custom authentication with fewer compromises than<br />

in this chapter.<br />

In Chapter 23, we develop a simple user authentication system that avoids some of<br />

the problems we faced here by using sessions to track variables between pages.<br />

In Chapter 27, we apply this approach to a real-world project <strong>and</strong> see how it can be<br />

used to implement a fine-grained authentication system.<br />

Further Reading<br />

The details of HTTP authentication are specified by RFC 2617, which is available at<br />

http://www.rfc-editor.org/rfc/rfc2617.txt<br />

The documentation for mod_auth, which controls basic authentication in Apache, can<br />

be found at http://httpd.apache.org/docs/2.0/mod/mod_auth.html.<br />

The documentation for mod_auth_mysql is inside the download archive. It is a tiny<br />

download, so even if you just want to find out more about it, downloading the archive<br />

to look at the readme file is not silly.<br />

Next<br />

The next chapter explains how to safeguard data at all stages of processing from input,<br />

through transmission, <strong>and</strong> in storage. It includes the use of SSL, digital certificates, <strong>and</strong><br />

encryption.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!