You are here

password_toggle.module in Password toggle 8

Same filename and directory in other branches
  1. 6 password_toggle.module
  2. 7 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
 */
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function password_toggle_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.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, FormStateInterface $form_state, $form_id) {
  if (in_array($form_id, array(
    'user_register_form',
    'user_login_form',
    'user_pass',
    'user_form',
  ))) {
    $form['#attached']['library'][] = 'password_toggle/password_toggle';
  }
}

Functions