Code

Cache password 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[$i]['name']  = $plugname;
68               $ret[$i]['class'] = $class;
69               $ret[$i]['object']= $test;
70               $ret[$i]['is_configurable']= $cfg;
71               $ret[$plugname]=$class;                    
72               $i++;
73             }
74           }
75         }
76       }
77       session::set("passwordMethod::get_available_methods",$ret);
78     }
79     return(session::get("passwordMethod::get_available_methods"));
80   }
81   
83   // Method to let password backends remove additional information besides
84   // the userPassword attribute
85   function remove_from_parent()
86   {
87   }
90   // Method to let passwords backends manage additional information
91   // besides the userAttribute entry
92   function set_password($password)
93   {
94   }
97   // Return true if this password method provides a configuration dialog
98   function is_configurable()
99   {
100     return FALSE;
101   }
104   // Provide a subdialog to configure a password method
105   function configure()
106   {
107     return "";
108   }
110   
111   // Save information to LDAP
112   function save($dn)
113   {
114   }
117   // Try to find out if it's our hash...
118   static function get_method($password_hash)
119   {
120     global $config;
122     $methods= passwordMethod::get_available_methods();
124     foreach ($methods['class'] as $class){
126         $test = new $class($config);
127         if(!$test->is_available())continue;
128         $method= $test->_extract_method($password_hash);
129         if ($method != ""){
130           $test->set_hash($method);
131           return $test;
132         }
133     }
135     msg_dialog::display(_("Error"), _("Cannot find a suitable password method for the current hash!"), ERROR_DIALOG);
137     return NULL;
138   }
141   function _extract_method($password_hash)
142   {
143     $hash= $this->get_hash_name();
144     if (preg_match("/^\{$hash\}/i", $password_hash)){
145       return $hash;
146     }
148     return "";
149   }
152   static function make_hash($password, $hash)
153   {
154     global $config;
156     $methods= passwordMethod::get_available_methods();
157     $tmp= new $methods[$hash]($config);
158     $tmp->set_hash($hash);
159     return $tmp->generate_hash($password);
160   }
163   function set_hash($hash)
164   {
165     $this->hash= $hash;
166   }
169   function get_hash()
170   {
171     return $this->hash;
172   }
175 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
176 ?>