You are here

function genpass_user_admin_settings_validate in Generate Password 7

Same name and namespace in other branches
  1. 8 genpass.module \genpass_user_admin_settings_validate()
  2. 6 genpass.module \genpass_user_admin_settings_validate()

User settings validation.

1 string reference to 'genpass_user_admin_settings_validate'
genpass_form_alter in ./genpass.module
Implementation of hook_form_alter()

File

./genpass.module, line 180

Code

function genpass_user_admin_settings_validate($form, &$form_state) {

  // Validate length of password
  $length = $form_state['values']['genpass_length'];
  if (!is_numeric($length) || $length < 5 || $length > 32) {
    form_set_error('genpass_length', t('The length of a generated password must be between 5 and 32.'));
    return;
  }

  // Validate allowed characters
  $chars = array_unique(preg_split('//', $form_state['values']['genpass_entropy'], -1, PREG_SPLIT_NO_EMPTY));
  if (count($chars) < $length) {
    form_set_error('genpass_entropy', t('The list of possible characters is not long or unique enough.'));
    return;
  }
  return $form;
}