Code

updated pwd methods
[gosa.git] / gosa-core / include / password-methods / class_password-methods.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class passwordMethod
24 {
25   var $config = false;
26   var $attrs= array();
27   var $hash= "";
29   // Konstructor
30   function passwordMethod($config)
31   {
32   }
35   function get_hash_name()
36   {
37   }
40   // this function returns all loaded classes for password encryption
41   static function get_available_methods()
42   {
43     global $class_mapping, $config;
44     $ret =false;
45     $i =0;
47     /* Only */
48     if(!session::is_set("passwordMethod::get_available_methods")){
49       foreach($class_mapping as $class => $path) {
50         if(preg_match('/passwordMethod/i', $class) && !preg_match("/^passwordMethod$/i", $class)){
51           $name = preg_replace ("/passwordMethod/i", "", $class);
52           $test = new $class($config, "");
53           if($test->is_available()) {
54             $plugs= $test->get_hash_name();
55             if (!is_array($plugs)){
56               $plugs= array($plugs);
57             }
59             foreach ($plugs as $plugname){
61               $cfg = $test->is_configurable();
63               $ret['name'][$i]= $plugname;
64               $ret['class'][$i]=$class;
65               $ret['is_configurable'][$i]= $cfg;
66               $ret['object'][$i]= $test;
67               $ret['desc'][$i] = $test->get_description();
68               $ret[$i]['name']  = $plugname;
69               $ret[$i]['class'] = $class;
70               $ret[$i]['object']= $test;
71               $ret[$i]['is_configurable']= $cfg;
72               $ret[$i]['desc'] = $test->get_description();
73               $ret[$plugname]=$class;                    
74               $i++;
75             }
76           }
77         }
78       }
79       session::set("passwordMethod::get_available_methods",$ret);
80     }
81     return(session::get("passwordMethod::get_available_methods"));
82   }
83   
85   function get_description()
86   {
87     return("");
88   }
91   // Method to let password backends remove additional information besides
92   // the userPassword attribute
93   function remove_from_parent()
94   {
95   }
98   // Method to let passwords backends manage additional information
99   // besides the userAttribute entry
100   function set_password($password)
101   {
102   }
105   // Return true if this password method provides a configuration dialog
106   function is_configurable()
107   {
108     return FALSE;
109   }
112   // Provide a subdialog to configure a password method
113   function configure()
114   {
115     return "";
116   }
118   
119   // Save information to LDAP
120   function save($dn)
121   {
122   }
125   // Try to find out if it's our hash...
126   static function get_method($password_hash,$dn = "")
127   {
128     global $config;
130     $methods= passwordMethod::get_available_methods();
132     foreach ($methods['class'] as $class){
134         $test = new $class($config,$dn);
135         if(!$test->is_available())continue;
136         $method= $test->_extract_method($password_hash);
137         if ($method != ""){
138           $test->set_hash($method);
139           return $test;
140         }
141     }
143     msg_dialog::display(_("Error"), _("Cannot find a suitable password method for the current hash!"), ERROR_DIALOG);
145     return NULL;
146   }
149   function _extract_method($password_hash)
150   {
151     $hash= $this->get_hash_name();
152     if (preg_match("/^\{$hash\}/i", $password_hash)){
153       return $hash;
154     }
156     return "";
157   }
160   static function make_hash($password, $hash)
161   {
162     global $config;
164     $methods= passwordMethod::get_available_methods();
165     $tmp= new $methods[$hash]($config);
166     $tmp->set_hash($hash);
167     return $tmp->generate_hash($password);
168   }
171   function set_hash($hash)
172   {
173     $this->hash= $hash;
174   }
177   function get_hash()
178   {
179     return $this->hash;
180   }
183 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
184 ?>