You are here

function _key_obscure_value in Key 7.3

Helper function to obscure a value.

Parameters

string $value: The value to obscure.

array $options: Options to use when obscuring the value.

Return value

string The obscured value.

1 call to _key_obscure_value()
_key_default_obscure_key_value in ./key.module
Default function to obscure a key value.

File

./key.module, line 898
Main Key functionality and hook implementations.

Code

function _key_obscure_value($value, $options = array()) {

  // Add default options.
  $options += array(
    'replacement_character' => '*',
    'fixed_length' => '',
    'visible_right' => 4,
  );
  if ($options['visible_right'] > 0) {
    $visible_right_chars = drupal_substr($value, $options['visible_right'] * -1);
  }
  else {
    $visible_right_chars = '';
  }
  $obscured_chars = '';
  if ($options['fixed_length']) {
    $obscured_chars = str_repeat($options['replacement_character'], $options['fixed_length'] - $options['visible_right']);
  }
  elseif (drupal_strlen($value) - $options['visible_right'] > 0) {
    $obscured_chars = str_repeat($options['replacement_character'], drupal_strlen($value) - $options['visible_right']);
  }
  return $obscured_chars . $visible_right_chars;
}