cvs: pear /Auth/Container File.php
| From: | Martin Jansen | Date: | Sun, 04 Nov 2001 17:02:06 +0000 |
| Subject: | cvs: pear /Auth/Container File.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-1258@lists.php.net to get a copy of this message | ||
mj Sun Nov 4 12:02:06 2001 EDT
Added files:
/pear/Auth/Container File.php
Log:
* New storage container to handle plaintext files.
# Currently it only supports MD5 encryption.
Index: pear/Auth/Container/File.php
+++ pear/Auth/Container/File.php
<?php
//
// +----------------------------------------------------------------------+
// | PHP version 4.0 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2001 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt.
|
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Martin Jansen <mj@php.net> |
// +----------------------------------------------------------------------+
//
// $Id: File.php,v 1.1 2001/11/04 17:02:06 mj Exp $
//
require_once "Auth/Container.php";
require_once "PEAR.php";
/**
* Storage driver for fetching login data from a textfile
*
* @author Martin Jansen <mj@php.net>
* @package Auth
* @version $Revision: 1.1 $
*/
class Auth_Container_File extends Auth_Container
{
/**
* Content of the password file
* @var string
*/
var $content = "";
// {{{ Constructor
/**
* Constructor of the container class
*
* @param $dsn string connection data or DB object
* @return object Returns an error object if something went wrong
*/
function Auth_Container_File($filename)
{
if (!is_file($filename)) {
return new PEAR_Error("Illegal filename.", 41, PEAR_ERROR_DIE);
}
if (!$this->content = @file($filename)) {
return new PEAR_Error("Error while reading file contents.", 41,
PEAR_ERROR_DIE);
}
}
// }}}
// {{{ fetchData()
/**
* Get user information from textfile
*
* @param string Username
* @param string Password
* @return boolean
*/
function fetchData($username, $password)
{
foreach ($this->content as $value) {
list($file_username, $file_password) = explode(":", $value);
if ($file_username == $username) {
$file_password = trim($file_password);
switch (strlen($file_password)) {
/**
* MD5 encryption
*/
case 32 : {
$compare_password = md5($password);
break;
}
default : {
$compare_password = $password;
}
}
if ($file_password == $compare_password) {
Auth::setAuth($username);
return true;
}
}
}
return false;
}
// }}}
}
?>