Posted by Toby A Inkster on 04/12/07 08:15
amygdala wrote:
> But the Validator class only checks each field seperately. In order to keep
> the Validator class as common as possible would you build a seperate Login
> class for instance? A class that has some custom validation methods? Or
> perhaps just insert custom validation methods in the User class?
class User
{
public static logon ($username, $password)
{
// Example query. You will want to protect against SQL
// injection here.
$q = "SELECT blah
FROM blah
WHERE username=$username
AND password=$password";
$result = run_query($q);
if (!$result)
return NULL;
$user = new User;
$user->load_data(/* blah */);
return $user;
}
}
This is an example of a User "factory". See "factory design pattern" in the
PHP manual. To use it:
$logged_in_user = User::logon($_POST['un'], $_POST['pw']);
if (!$logged_in_user)
echo "Login failed.";
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there!
[Back to original message]
|