clearPassword = $data[0]; if (!$this -> config['ldap_options']['encode']) { $this -> config['ldap_options']['encode'] = 'md5crypt'; } switch($this -> config['ldap_options']['encode']) { case 'crypt': if ($this -> config['ldap_options']['no_random_crypt_salt']) { return array('{CRYPT}' . crypt($this -> clearPassword,substr($this -> clearPassword,0,2))); } else { return array('{CRYPT}' . crypt($this -> clearPassword,$this -> getSalt(2))); } break; case 'ext_des': if ( ! defined( 'CRYPT_EXT_DES' ) || CRYPT_EXT_DES == 0 ) { LSerror :: addErrorCode('LSattr_ldap_password_01','ext_des'); } else { return array('{CRYPT}' . crypt( $this -> clearPassword, '_' . $this -> getSalt(8) )); } break; case 'blowfish': if( ! defined( 'CRYPT_BLOWFISH' ) || CRYPT_BLOWFISH == 0 ) { LSerror :: addErrorCode('LSattr_ldap_password_01','blowfish'); } else { return array('{CRYPT}' . crypt( $this -> clearPassword, '$2a$12$' . $this -> getSalt(13) )); } break; case 'sha': if( function_exists('sha1') ) { return array('{SHA}' . base64_encode( pack( 'H*' , sha1( $this -> clearPassword ) ) )); } elseif( function_exists( 'mhash' ) ) { return array('{SHA}' . base64_encode( mhash( MHASH_SHA1, $this -> clearPassword ) )); } else { LSerror :: addErrorCode('LSattr_ldap_password_01','sha'); } break; case 'ssha': if( function_exists( 'mhash' ) && function_exists( 'mhash_keygen_s2k' ) ) { mt_srand( (double) microtime() * 1000000 ); $salt = mhash_keygen_s2k( MHASH_SHA1, $this -> clearPassword, substr( pack( "h*", md5( mt_rand() ) ), 0, 8 ), 4 ); return array("{SSHA}".base64_encode( mhash( MHASH_SHA1, $this -> clearPassword.$salt ).$salt )); } else { LSerror :: addErrorCode('LSattr_ldap_password_01','ssha'); } break; case 'smd5': if( function_exists( 'mhash' ) && function_exists( 'mhash_keygen_s2k' ) ) { mt_srand( (double) microtime() * 1000000 ); $salt = mhash_keygen_s2k( MHASH_MD5, $password_clear, substr( pack( "h*", md5( mt_rand() ) ), 0, 8 ), 4 ); return array("{SMD5}".base64_encode( mhash( MHASH_MD5, $password_clear.$salt ).$salt )); } else { LSerror :: addErrorCode('LSattr_ldap_password_01','smd5'); } break; case 'md5': return array('{MD5}' . base64_encode( pack( 'H*' , md5( $this -> clearPassword ) ) )); break; case 'md5crypt': if( ! defined( 'CRYPT_MD5' ) || CRYPT_MD5 == 0 ) { LSerror :: addErrorCode('LSattr_ldap_password_01','md5crypt'); } else { return array('{CRYPT}'.crypt($this -> clearPassword,'$1$'.$this -> getSalt().'$')); } break; case 'clear': return array($this -> clearPassword); break; } LSerror :: addErrorCode('LSattr_ldap_password_01',$this -> config['ldap_options']['encode']); return array($this -> clearPassword); } /** * Return salt (random string) * * @param[in] integer Number of caracters in this salt * * @retval string A salt */ function getSalt($length=8) { $pattern = "1234567890abcdefghijklmnopqrstuvwxyz"; $key = $pattern{rand(0,35)}; for($i=1;$i<$length;$i++) { $key .= $pattern{rand(0,35)}; } return $key; } /** * Return the password in clear text * * @retval string The password in clear text */ function getClearPassword() { return $this -> clearPassword; } } /** * Error Codes **/ LSerror :: defineError('LSattr_ldap_password_01', _("LSattr_ldap_password : Encoding type %{type} is not supported. This password will be stored in clear text.") ); ?>