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.

570 Chapter 27 Building User Authentication <strong>and</strong> Personalization<br />

This system should enable users to log in <strong>and</strong> store their personal bookmarks <strong>and</strong> to<br />

get recommendations for other sites that they might like to visit based on their personal<br />

preferences.<br />

These solution components fall into three main categories:<br />

n You need to be able to identify individual users.You should also have some way of<br />

authenticating them.<br />

n You need to be able to store bookmarks for an individual user. Users should be<br />

able to add <strong>and</strong> delete bookmarks.<br />

n You need to be able to recommend to users sites that might appeal to them, based<br />

on what you know about them already.<br />

Now that you know the idea behind the project, you can begin designing the solution<br />

<strong>and</strong> its components. Let’s look at possible solutions to each of the three main requirements<br />

listed.<br />

User Identification <strong>and</strong> Personalization<br />

Several alternatives can be used for user authentication, as you have seen elsewhere in<br />

this book. Because you want to tie users to some personalization information, you can<br />

store the users’ logins <strong>and</strong> passwords in a <strong>MySQL</strong> database <strong>and</strong> authenticate against it.<br />

If you are going to let users log in with usernames <strong>and</strong> passwords, you will need the<br />

following components:<br />

n Users should be able to register their usernames <strong>and</strong> passwords.You need some<br />

restrictions on the length <strong>and</strong> format of each username <strong>and</strong> password.You should<br />

store passwords in an encrypted format for security reasons.<br />

n Users should be able to log in with the details they supplied in the registration<br />

process.<br />

n Users should be able to log out after they have finished using a site.This capability<br />

is not particularly important if people use the site from their home PC but is very<br />

important for security if they use the site from a shared PC.<br />

n The site needs to be able to check whether a particular user is logged in <strong>and</strong><br />

access data for a logged-in user.<br />

n Users should be able to change their passwords as an aid to security.<br />

n Users should be able to reset their passwords without needing personal assistance<br />

from you.A common way of doing this is to send a user’s password to him in an<br />

email address he has nominated at registration.This means you need to store his<br />

email address at registration. Because you store the passwords in an encrypted form<br />

<strong>and</strong> cannot decrypt the user’s original password, you actually need to generate a new<br />

password, set it, <strong>and</strong> mail it to the user.

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

Saved successfully!

Ooh no, something went wrong!