Hello,

On the User settings page (www.example.com/admin/user/settings) there is a checkbox that will allow users to select their own password on registration. The registration page then has two input boxes for Password and Confirm Password, however I would like to only have one input box for Password and no Confirm Password.

Many sites require only one entry of a password, ie Twitter and Facebook. This does increase the possibility of mistakes to be made when registering, but if the user makes a mistake in typing the password he/she can easily go to Request New Password and be sent a one-time login link.

Would anyone please be able to assist in creating a custom module to remove the Confirm Password input box?

Thank you very much!

Comments

Bilmar’s picture

With help from the drupal community, I have been set in the right direction.
Once I am able to get this to work I will post back with my solution.
Thanks!

Bilmar’s picture

Thanks to S13 and Raj for all the help!

This is the code that worked in my case bc I was using LoginToboggan module (must go into a custom module)

function mymodule_form_user_register_alter(&$form, &$form_state) {
  $form['account']['pass']['#type'] = 'password';
  $form['account']['pass']['#title'] = 'Password';
}

This would be the code that would most likely work for you.

function mymodule_form_user_register_alter(&$form, &$form_state) {
  $form['pass']['#type'] = 'password';
  $form['pass']['#title'] = 'Password';
}

Things I learned:
1) the code must go into a custom module
2) the code will not work in template.php as in example below.

function mytheme_preprocess_user_register(&$vars) {
  $vars['form']['account']['pass']['#type'] = 'password';
  $vars['form']['account']['pass']['#title'] = 'Password';
}

3) check out the $form array structure by typing the below at the top of the user-register.tpl.php file

<?php print_r($form); ?>

or for a cleaner layout enable devel module and use this code

<?php dprint_r($form); ?>

Regards

gorav.singal’s picture

As you wrote, this code must be in a module, not in template.php

I'm doing the same, and writing the code in template.php, and it works for me.

Bilmar’s picture

Would you kindly share the code used in template.php that allows the same functionality?

Thank you

imDhaval’s picture


function mymodule_form_user_register_alter(&$form, &$form_state) {
  $form['pass']['#type'] = 'password';
  $form['pass']['#title'] = 'Password';
}

this is my module file, but it is not working for me

kgaut’s picture

function MYMODULE_form_user_register_form_alter(&$form,\Drupal\Core\Form\FormStateInterface $form_state,$form_id) {
  $form['account']['pass']['#type'] = 'password';
  $form['account']['pass']['#title'] = t('Mot de passe');
}
ccshannon’s picture

This code adds a new self-standing Password field to a registration form. It does not, however, remove the existing Password/Confirm Password widget. You end up with three fields (Password, Confirm password, and a second Password), and they conflict with one another, making registration impossible. How does one actually remove the legacy Password/Confirm widget? Thx.

EDIT UPDATE: Argh, nevermind. I'm working with two different D8 projects ... hint to anyone not having success ... if you're getting three fields, try '$form['account']['pass']' instead of '$form['pass']' or vice versa.

gisle’s picture

This is a forum to request paid help. Please do not use it for discussions.

- gisle