You are here

function genpass_register_validate in Generate Password 6

Same name and namespace in other branches
  1. 8 genpass.module \genpass_register_validate()
  2. 5 genpass.module \genpass_register_validate()
  3. 7 genpass.module \genpass_register_validate()

User registration validation.

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

File

./genpass.module, line 192

Code

function genpass_register_validate($form, &$form_state) {
  if (empty($form_state['values']['pass']) && !form_get_errors()) {

    // Generate and set password
    $pass = genpass_generate();
    $pass_item =& _genpass_get_form_item($form, 'pass');
    form_set_value($pass_item, $pass, $form_state);
    $display = variable_get('genpass_display', GENPASS_DISPLAY_BOTH);

    // Administrator created the user.
    if ($_GET['q'] == 'admin/user/user/create') {
      $message = t('Since you did not provide a password, it was generated automatically for this account.');
      if (in_array($display, array(
        GENPASS_DISPLAY_ADMIN,
        GENPASS_DISPLAY_BOTH,
      ))) {
        $message .= ' ' . t('The password is: <strong class="nowrap">@password</strong>', array(
          '@password' => $pass,
        ));
      }
    }
    elseif ($form_state['values']['genpass_mode'] == GENPASS_OPTIONAL) {
      $message = t('Since you did not provide a password, it was generated for you.');
      if (in_array($display, array(
        GENPASS_DISPLAY_USER,
        GENPASS_DISPLAY_BOTH,
      ))) {
        $message .= ' ' . t('Your password is: <strong class="nowrap">@password</strong>', array(
          '@password' => $pass,
        ));
      }
    }
    elseif ($form_state['values']['genpass_mode'] == GENPASS_RESTRICTED && in_array($display, array(
      GENPASS_DISPLAY_USER,
      GENPASS_DISPLAY_BOTH,
    ))) {
      $message = t('The following password was generated for you: <strong class="nowrap">@password</strong>', array(
        '@password' => $pass,
      ));
    }
    if (!empty($message)) {
      drupal_set_message($message);
    }
  }
  return $form;
}