Core  3.2
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  * @package FDL
5 */
6 /**
7  * ldap authentication provider
8  *
9  * @author Anakeen
10  * @version $Id: $
11  * @package FDL
12  */
13 /**
14  */
15 
16 include_once ("WHAT/Class.Provider.php");
17 class fileProvider extends Provider
18 {
19  private function readPwdFile($pwdfile)
20  {
21  $fh = fopen($pwdfile, 'r');
22  if ($fh == FALSE) {
23  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Error: opening file " . $pwdfile);
24  $this->errno = 0;
25  return FALSE;
26  }
27  $passwd = array();
28  while ($line = fgets($fh)) {
29  $el = explode(':', $line);
30  if (count($el) != 2) {
31  continue;
32  }
33  $passwd{$el[0]} = trim($el[1]);
34  }
35  fclose($fh);
36  $this->errno = 0;
37  return $passwd;
38  }
39 
40  public function validateCredential($username, $password)
41  {
42 
43  static $pwdFile = false;
44 
45  if (!array_key_exists('authfile', $this->parms)) {
46  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Error: authfile parm is not defined at __construct");
47  $this->errno = 0;
48  return FALSE;
49  }
50 
51  if ($pwdFile === false) $pwdFile = $this->readPwdFile($this->parms{'authfile'});
52  if ($pwdFile === false) {
53  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Error: reading authfile " . $this->parms{'authfile'});
54  $this->errno = 0;
55  return false;
56  }
57 
58  if (!array_key_exists($username, $pwdFile)) {
59  $this->errno = 0;
60  return FALSE;
61  }
62  $ret = preg_match("/^(..)/", $pwdFile[$username], $salt);
63  if ($ret == 0) {
64  $this->errno = 0;
65  return FALSE;
66  }
67 
68  if ($pwdFile[$username] == crypt($password, $salt[0])) {
69  $this->errno = 0;
70  return true;
71  }
72 
73  $this->errno = 0;
74  return false;
75  }
76 }
$ret
validateCredential($username, $password)
← centre documentaire © anakeen