Code

Fixed one department level up <- action in management lists.
[gosa.git] / gosa-core / include / password-methods / class_password-methods-crypt.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 passwordMethodCrypt extends passwordMethod
24 {
25   function passwordMethodCrypt($config)
26   {
27   }
30   function is_available()
31   {
32     if(function_exists("crypt")){
33       return true;
34     }else{
35       return false;
36     }
37   }
40   function generate_hash($pwd)
41   {
42     if ($this->hash == "crypt/standard-des"){
43       $salt = "";
44       for ($i = 0; $i < 2; $i++) {
45           $salt .= get_random_char();
46       }
47     }
49     if ($this->hash == "crypt/enhanced-des"){
50       $salt = "_";
51       for ($i = 0; $i < 8; $i++) {
52           $salt .= get_random_char();
53       }
54     }
56     if ($this->hash == "crypt/md5"){
57       $salt = "\$1\$";
58       for ($i = 0; $i < 8; $i++) {
59           $salt .= get_random_char();
60       }
61       $salt .= "\$";
62     }
64     if ($this->hash == "crypt/blowfish"){
65       $salt = "\$2a\$07\$";
66       for ($i = 0; $i < CRYPT_SALT_LENGTH; $i++) {
67           $salt .= get_random_char();
68       }
69       $salt .= "\$";
70     }
72     return "{CRYPT}".crypt($pwd, $salt);
73   }
76   function get_hash_name()
77   {
78     $hashes= array();
79     if (CRYPT_STD_DES == 1) {
80       $hashes[]= "crypt/standard-des";
81     }
83     if (CRYPT_EXT_DES == 1) {
84       $hashes[]= "crypt/enhanced-des";
85     }
87     if (CRYPT_MD5 == 1) {
88       $hashes[]= "crypt/md5";
89     }
91     if (CRYPT_BLOWFISH == 1) {
92       $hashes[]= "crypt/blowfish";
93     }
95     return $hashes;
96   }
99   function _extract_method($password_hash)
100   {
101     if (!preg_match('/^{crypt}/i', $password_hash)){
102       return "";
103     }
105     $password_hash= preg_replace('/^{[^}]+}!?/', '', $password_hash);
107     if (preg_match("/^[a-zA-Z0-9.\/][a-zA-Z0-9.\/]/", $password_hash)){
108       return "crypt/standard-des";
109     }
111     if (preg_match("/^_[a-zA-Z0-9.\/]/", $password_hash)){
112       return "crypt/enhanced-des";
113     }
114     
115     if (preg_match('/^\$1\$/', $password_hash)){
116       return "crypt/md5";
117     }
119     if (preg_match('/^(\$2\$|\$2a\$)/', $password_hash)){
120       return "crypt/blowfish";
121     }
123     return "";
124   }
128 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
129 ?>