You are here

password_toggle.module in Password toggle 7

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

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

File

password_toggle.module
View source
<?php

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

/**
 * Implements 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.");
  }
}

/**
 * Implements 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_and_css();
  }
}

/**
 * Implements hook_init().
 *
 * Add the password toggle JS and CSS 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_and_css();
    }
  }
}

/**
 * Wrapper function to add the password toggle JS and CSS files.
 */
function password_toggle_add_js_and_css() {
  $path = drupal_get_path('module', 'password_toggle');
  drupal_add_js($path . '/password_toggle.js');
  drupal_add_css($path . '/password_toggle.css');
}

Functions

Namesort descending Description
password_toggle_add_js_and_css Wrapper function to add the password toggle JS and CSS files.
password_toggle_form_alter Implements hook_form_alter().
password_toggle_help Implements hook_help().
password_toggle_init Implements hook_init().