crypto->getRandomString(31); if (_elgg_services()->datalist->set('__site_secret__', $secret)) { return $secret; } return false; } /** * Returns the site secret. * * Used to generate difficult to guess hashes for sessions and action tokens. * * @param bool $raw If true, a binary key will be returned * * @return string Site secret. * @access private */ function get($raw = false) { $secret = _elgg_services()->datalist->get('__site_secret__'); if (!$secret) { $secret = init_site_secret(); } if ($raw) { // try to return binary key if ($secret[0] === 'z') { // new keys are "z" + base64URL $base64 = strtr(substr($secret, 1), '-_', '+/'); $key = base64_decode($base64); if ($key !== false) { // on failure, at least return string key :/ return $key; } } else { // old keys are hex return hex2bin($secret); } } return $secret; } /** * Get the strength of the site secret * * If "weak" or "moderate" is returned, this assumes we're running on the same system that created * the key. * * @return string "strong", "moderate", or "weak" * @access private */ function getStrength() { $secret = get_site_secret(); if ($secret[0] !== 'z') { $rand_max = getrandmax(); if ($rand_max < pow(2, 16)) { return 'weak'; } if ($rand_max < pow(2, 32)) { return 'moderate'; } } return 'strong'; } }