1

I would like my users to log in through 'Email' and 'Last Name', rather than 'User Name' and 'Password'. I did manage to swap 'User Name' with 'Email', but I cannot replace 'Password' with the user's 'Last Name'.

I have added another customer profile with two new fields, i.e., 'First Name' and 'Last Name' and now want the field 'Last Name' to be used in place of 'Password'.

I tried everything. Any help or guideline will be highly appreciated.

6
  • you would need to create a new form with validation, create session information, etc - you can't simply swap fields. Your better option is to change the text 'password' to 'last name' in the existing user login form
    – Geoff
    Jun 16, 2015 at 22:22
  • The question has to be asked, how is using your lastname as the password secure? Given some publicly available information, any user could quite easily guess another user's login details. Jun 16, 2015 at 22:36
  • David its a sort of site where priority is to give easy n quick access to users without any email/password verifications. Once logged in, the site doesn't provide any info that could be of help to another user who guesses login details, nor it give any permissions to make changes to the account. Therefore security is not a issue.
    – Jennifer87
    Jun 17, 2015 at 0:34
  • @Geoff I am pretty new in drupal and php. I can create a form with validation, but creating session info could be a bit tough. Do u think you can share some coding/snippet related to session info that I can add in my validation form? Thanks
    – Jennifer87
    Jun 17, 2015 at 0:44
  • 2
    If the point of doing this is giving "easy n quick access to users without any email/password verifications" - why require a login at all? Why not just have all information on the site publicly available? That would provide even quicker access to it. Jun 17, 2015 at 4:30

1 Answer 1

0

You can do this by using a module called String overrides to redefine the strings exposed to your users during login and on their profile page.

Navigate to Administration » Configuration » Regional and language » String overrides and fille in the following and click "Save configuration":

enter image description here

Now, login will look like this to your users:

enter image description here

Note that this just renames the fields. This means that the last name will not have its own field and it will not be displayed on the user's profile page. It is not clear from your question whether this will be a problem.

However, if you want a real "Last name" field, and you want to use this field for authentication, you can do this by creating a small module that uses hook_form_FORM_ID_alter() to make a couple of changes to the login form:

  1. Hide the password field.
  2. Add "Last name" as a field.

Now, in the form validation, check that the value of the "Last name" field matches the last name in the user's profile, and if it does, fill in the hidden password field with the correct password. If you use the same password for all users in this set up, it can be hard-coded in your form validation. This will make Drupal take care of all the heavy lifting of creating a session, book-keeping of logins, etc.

As for the (in)security of using the last name instead of a real password as a login credential, I'll take your word for security not being an issue here. However, I am puzzled by why want this, so I have added a question about it as a comment.

1
  • Thanks Free Radical. I was worried that I have to write code for sessions and book keeping, which can take forever, but you have made this job very easy for me .. All i need to do is alter/validate the form. Thanks again!
    – Jennifer87
    Jun 19, 2015 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.