You are here

public static function SimpleLdap::salt in Simple LDAP 7.2

Same name and namespace in other branches
  1. 7 SimpleLdap.class.php \SimpleLdap::salt()

Generates a random salt of the given length.

2 calls to SimpleLdap::salt()
SimpleLdap::hash in ./SimpleLdap.class.php
Hash a string for use in an LDAP password field.
SimpleLdap::hash in ./SimpleLdap.class.php
Hash a string for use in an LDAP password field.

File

./SimpleLdap.class.php, line 148
Class defining base Simple LDAP functionallity.

Class

SimpleLdap
Simple LDAP class.

Code

public static function salt($length) {
  $possible = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ./';
  $str = '';
  while (strlen($str) < $length) {
    $str .= substr($possible, rand() % strlen($possible), 1);
  }
  return $str;
}