Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.fileProvider.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * ldap authentication provider
9  *
10  * @author Anakeen 2009
11  * @version $Id: $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  */
15 /**
16  */
17 
18 include_once ("WHAT/Class.Provider.php");
19 class fileProvider extends Provider
20 {
21 
22  private function readPwdFile($pwdfile)
23  {
24  $fh = fopen($pwdfile, 'r');
25  if ($fh == FALSE) {
26  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Error: opening file " . $pwdfile);
27  $this->errno = 0;
28  return FALSE;
29  }
30  $passwd = array();
31  while ($line = fgets($fh)) {
32  $el = explode(':', $line);
33  if (count($el) != 2) {
34  continue;
35  }
36  $passwd{$el[0]} = trim($el[1]);
37  }
38  fclose($fh);
39  $this->errno = 0;
40  return $passwd;
41  }
42 
43  public function validateCredential($username, $password)
44  {
45 
46  static $pwdFile = false;
47 
48  if (!array_key_exists('authfile', $this->parms)) {
49  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Error: authfile parm is not defined at __construct");
50  $this->errno = 0;
51  return FALSE;
52  }
53 
54  if ($pwdFile === false) $pwdFile = $this->readPwdFile($this->parms{'authfile'});
55  if ($pwdFile === false) {
56  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Error: reading authfile " . $this->parms{'authfile'});
57  $this->errno = 0;
58  return false;
59  }
60 
61  if (!array_key_exists($username, $pwdFile)) {
62  $this->errno = 0;
63  return FALSE;
64  }
65  $ret = preg_match("/^(..)/", $pwdFile[$username], $salt);
66  if ($ret == 0) {
67  $this->errno = 0;
68  return FALSE;
69  }
70 
71  if ($pwdFile[$username] == crypt($password, $salt[0])) {
72  $this->errno = 0;
73  return true;
74  }
75 
76  $this->errno = 0;
77  return false;
78  }
79 
80  public function validateAuthorization($opt)
81  {
82  $this->errno = 0;
83  return TRUE;
84  }
85 }
86 ?>
← centre documentaire © anakeen - published under CC License - Dynacase