You are here

function ldap_servers_random_salt in Lightweight Directory Access Protocol (LDAP) 8.2

Same name and namespace in other branches
  1. 7.2 ldap_servers/ldap_servers.encryption.inc \ldap_servers_random_salt()
  2. 7 ldap_servers/ldap_servers.encryption.inc \ldap_servers_random_salt()

Return a random salt of a given length for crypt-style passwords

Parameters

int length: The requested length.

Return value

string A (fairly) random salt of the requested length.

File

ldap_servers/ldap_servers.encryption.inc, line 20
Provides functions for encryption/decryption. http://stackoverflow.com/questions/2448256/php-mcrypt-encrypting-decrypt...

Code

function ldap_servers_random_salt($length) {
  $possible = '0123456789' . 'abcdefghijklmnopqrstuvwxyz' . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . './';
  $salt = "";
  mt_srand((double) microtime() * 1000000);
  while (strlen($salt) < $length) {
    $salt .= substr($possible, rand() % strlen($possible), 1);
  }
  return $salt;
}