|
|
|
<?
/*
* account.php3
*
* @(#) $Header: /cvsroot/enanet/accounts.php3,v 1.8 1998/05/11 23:19:41 mlemos Exp $
*
* E na Net service
*
* This information is CONFIDENTIAL and PROPRIETARY
* (C) Copyright Manuel Lemos. All Rights Reserved.
*
* $Log: accounts.php3,v $
* Revision 1.8 1998/05/11 23:19:41 mlemos
* Moved the Function to crypt passwords and renamed to AccountCryptPassword.
*
* Revision 1.7 1998/04/01 02:14:43 mlemos
* Added support to convert user names and password to lower case.
*
* Revision 1.6 1998/03/28 15:43:46 mlemos
* Replaced md5 by crypt based password encription and lookup.
*
* Revision 1.5 1998/03/27 22:16:05 mlemos
* Fixed missing password argument in the ModifyAccessAccount method.
*
* Revision 1.4 1998/03/27 20:51:56 mlemos
* Made CheckPassword method consider deleted accounts marked with passwords
* set to *.
*
* Revision 1.3 1998/03/27 05:27:26 mlemos
* Moved the account lookup code to a separate method.
*
* Revision 1.2 1998/03/27 02:49:33 mlemos
* Added methods AddAccessAccount, SaveAccessAccounts.
* Added PHP error to error messages returned from method ReadAccounts method.
* Removed the end of line character before parsing an account line.
* Added quotes to the user name account entries.
* Corrected the accesses to the accounts array in CheckPassword method.
*
* Revision 1.1 1998/03/26 21:40:19 mlemos
* Initial revision.
*
*
*
*/
Function AccountCryptPassword($password,$salt)
{
if($salt== "")
{
srand(time());
$random=rand();
$itoa64= "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
$salt=substr($itoa64,$random % 64,1).substr($itoa64,($random/64) % 64,1);
}
return(crypt($password,$salt));
}
class access_accounts
{
var $password_file= "";
var $accounts=array();
var $convert_to_lower_case=0;
Function ReadAccounts($password_file)
{
global $php_errormsg;
$passwd=@File($password_file);
if(GetType($passwd)!= "array")
return( "can not read password file \"$password_file\" ($php_errormsg)");
for($account=0,$accounts=array();$account<count($passwd);$account++)
{
if(($line=strtok($passwd[$account], "\n"))== "")
$line=$passwd[$account];
if(($user=strtok($line, ":"))== "")
return( "invalid user in line $account of password file \"$password_file\"");
if($this->convert_to_lower_case)
$user=strtolower($user);
$accounts[$account][ "user"]= "$user";
$accounts[$account][ "password"]=strtok( ":");
}
$this->accounts=$accounts;
$this->password_file=$password_file;
return( "");
}
Function LookupAccount($user)
{
if($this->convert_to_lower_case)
$user=strtolower($user);
for($account=0;$account<count($this->accounts);$account++)
{
if($this->accounts[$account][ "user"]==$user)
break;
}
return($account);
}
Function CheckPassword($user,$password)
{
if($user== "")
return( "empty user");
if($password== "")
return( "empty password");
if($this->convert_to_lower_case)
{
$user=strtolower($user);
$password=strtolower($password);
}
if(($account=$this->LookupAccount($user))<count($this->accounts))
{
if($this->accounts[$account][ "password"]== "*")
return( "account was deleted");
if($this->accounts[$account][ "password"]==AccountCryptPassword($password,substr($this->accounts[$account]
[ "password"],0,2)))
return( "");
else
return( "password does not match");
}
return( "unknown user");
}
Function AddAccessAccount($user,$password)
{
if($this->convert_to_lower_case)
{
$user=strtolower($user);
$password=strtolower($password);
}
$account=count($this->accounts);
$this->accounts[$account][ "user"]=$user;
$this->accounts[$account][ "password"]=AccountCryptPassword($password, "");
return($account);
}
Function SaveAccessAccounts()
{
global $php_errormsg;
if($this->password_file== "")
return( "it was not defined the password file");
if(($file=@fopen($this->password_file, "w"))==0)
return( "can not open password file \"$password_file\" ($php_errormsg)");
for($account=0;$account<count($this->accounts);$account++)
{
$user=$this->accounts[$account][ "user"];
if($this->convert_to_lower_case)
$user=strtolower($user);
if(fputs($file,sprintf( "%s:%s\n",$user,$this->accounts[$account][ "password"]))==0)
return( "can not write to password file \"$password_file\" ($php_errormsg)");
}
fclose($file);
return( "");
}
Function DeleteAccount($user)
{
if($this->convert_to_lower_case)
$user=strtolower($user);
if(($account=$this->LookupAccount($user))<count($this->accounts))
{
if($this->accounts[$account][ "password"]!= "*")
{
$this->accounts[$account][ "password"]= "*";
return( "");
}
else
return( "account was already deleted");
}
return( "unknown user");
}
Function ModifyAccessAccount($user,$password)
{
if($this->convert_to_lower_case)
{
$user=strtolower($user);
$password=strtolower($password);
}
if(($account=$this->LookupAccount($user))>=count($this->accounts))
return( "unknown user");
$this->accounts[$account][ "password"]=AccountCryptPassword($password, "");
return( "");
}
};
?> |
|
| Easy upload class Categories : PHP Classes, Filesystem, HTTP, PHP | | | file class , uploade file , download file already uploaded on another website Categories : PHP, PHP Classes, Filesystem, Web Services | | | Simple pipe delimited file export program that downloads to a local machine Categories : PHP, Filesystem, Databases, MySQL, HTTP | | | Remote File Saving with PHP - Download and serve a remote file. The content of the file will be updated at fixed intervals. Categories : PHP, Filesystem, Cache, Sockets, HTTP | | | Remote File Size Categories : PHP, Filesystem, HTTP, Sockets | | | 3 lines of Code to extract Tar, Zip, Gzip etc.. Categories : PHP, Filesystem, PHP Classes, Compression | | | Gonx Proxy - This class is meant to act as an HTTP proxy to serve pages of a remote server as if they were local pages.
Categories : PHP, PHP Classes, HTTP | | | Remote Archive (Zip, Tar, Gzip) downloader with FTP and local extration support Categories : PHP, FTP, Filesystem, PHP Classes, Compression | | | A File Browser Class.To Read Drives,Directories and Files .Files writing is also possible Categories : PHP, PHP Classes, Filesystem | | | Search and Replace Text : Searches Files for Specified Text and Replaces It by a Given Text Categories : PHP, PHP Classes, Search, Filesystem | | | Force file download Categories : PHP, Filesystem, HTTP, Program Execution | | | How to let a user download a picture by clicking on it instead of needing to right click and Save-As. Categories : HTTP, PHP, HTML and PHP, Filesystem | | | Compare two texts and display a block of text with the differences between them. Categories : PHP, PHP Classes, Filesystem, Strings, Arrays | | | An efficient iterative and buffered text file reader Categories : PHP, Classes and Objects, Filesystem, PHP Classes, Log Files | | | PHP4 DirectoryIterator Class Categories : PHP, PHP Classes, Filesystem, Directories | |
|
|
|