You are here

password_toggle.module in Password toggle 6

Same filename and directory in other branches
  1. 8 password_toggle.module
  2. 7 password_toggle.module

password_toggle.module Simple module that adds a checkbox to toggle password masking on login forms.

@see: http://www.alistapart.com/articles/the-problem-with-passwords/ and http://www.vileworks.com/password-unmasking

File

password_toggle.module
View source
<?php

/**
 * @file password_toggle.module
 * Simple module that adds a checkbox to toggle password masking on login forms.
 *
 * @see: http://www.alistapart.com/articles/the-problem-with-passwords/ and
 * http://www.vileworks.com/password-unmasking
 */

/**
 * Implementation of hook_help().
 */
function password_toggle_help($path, $arg) {
  switch ($path) {
    case 'admin/help#password_toggle':
      return t("The Password toggle module adds a checkbox to password fields which toggles the masking of the password; that is, clicking the checkbox changes the '•' characters to the typed characters and back again. This allows users to verify they have typed the correct password, but also retain privacy if required.");
  }
}

/**
 * Implementation of hook_form_alter().
 */
function password_toggle_form_alter(&$form, $form_state, $form_id) {
  if (in_array($form_id, array(
    'user_profile_form',
    'user_register',
    'user_login',
    'user_login_block',
  ))) {
    password_toggle_add_js();
  }
}

/**
 * Implementation of hook_init().
 *
 * Add the password toggle JS to specific pages.
 */
function password_toggle_init() {
  global $user;

  // Only act for anonymous users.
  if ($user->uid == 0) {

    // Pages where this should show:
    // The login page.
    if (arg(0) == 'user' && arg(1) == NULL) {
      password_toggle_add_js();
    }
  }
}

/**
 * Preprocessor for block.tpl.php.
 *
 * Add the password toggle JS when the login block is displayed.
 */
function Xpassword_toggle_preprocess_block(&$variables) {
  if ($variables['block']->module == 'user' && $variables['block']->delta == 0) {
    password_toggle_add_js();
  }
}

/**
 * Wrapper function to add the password toggle JS.
 */
function password_toggle_add_js() {
  drupal_add_js(drupal_get_path('module', 'password_toggle') . '/password_toggle.js');
}

Functions

Namesort descending Description
password_toggle_add_js Wrapper function to add the password toggle JS.
password_toggle_form_alter Implementation of hook_form_alter().
password_toggle_help Implementation of hook_help().
password_toggle_init Implementation of hook_init().
Xpassword_toggle_preprocess_block Preprocessor for block.tpl.php.