function _ldap_servers_encrypt in Lightweight Directory Access Protocol (LDAP) 8.2
Same name and namespace in other branches
- 7.2 ldap_servers/ldap_servers.encryption.inc \_ldap_servers_encrypt()
- 7 ldap_servers/ldap_servers.encryption.inc \_ldap_servers_encrypt()
Encrypt Password Method
Parameters
string clear_txt: Plaintext password.
Return value
string Encrypted text, formatted for use as an LDAP password.
1 call to _ldap_servers_encrypt()
- ldap_servers_encrypt in ldap_servers/
ldap_servers.module
File
- ldap_servers/
ldap_servers.encryption.inc, line 86 - Provides functions for encryption/decryption. http://stackoverflow.com/questions/2448256/php-mcrypt-encrypting-decrypt...
Code
function _ldap_servers_encrypt($clear_txt, $enc_type = NULL) {
if (!$enc_type) {
$enc_type = config('ldap_servers.settings')
->get('encryption');
}
if ($enc_type == LDAP_SERVERS_ENC_TYPE_CLEARTEXT) {
return $clear_txt;
}
$key = config('ldap_servers.settings')
->get('encrypt_key');
switch ($enc_type) {
case LDAP_SERVERS_ENC_TYPE_BLOWFISH:
// Blowfish
$td = mcrypt_module_open('blowfish', '', LDAP_SERVERS_CYPHER_MODE, '');
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
mcrypt_generic_init($td, $key, $iv);
$crypttext = mcrypt_generic($td, $clear_txt);
mcrypt_generic_deinit($td);
$cipher_txt = $iv . $crypttext;
break;
default:
// Cleartext
$cipher_txt = $clear_txt;
}
return base64_encode($cipher_txt);
}