Ted Bowman's picture

I recently ported my old module Password Require, which allows password protecting any form in Drupal, to Drupal 7.  This module was originally created for my presentation at the Florida Drupal Camp in 2010, as an introduction to module development.


It is an example of how little code you need to add useful functionality to Drupal. But of course after you add an administration UI and try to make it generally easier to use the code starts to add up, not tons but more than a good first module example.

So as a learning tool for those who want to start learning module development for Drupal I have trimmed this module down to 36 lines of code(not counting the comments).

Download the simplified Password Require module.

The video above demonstrates the functionality of the module as it appears on Drupal.org and the video below gives an explanation of how the trimmed down code works.  I have also attached the simplified version of the module to this post.

The module demonstrates the use of hook_form_alter and using a validation function to validate the input of an individual form element.  It consists of only 2 php functions.

As an example of the difference between coding a contrib module for Drupal.org and a custom module for a client, the shortened version of the module is probably closer to what I would make for a client who needed the custom functionality for their site(if the module didn't already exist).  Often a client is not going to want to pay for the time it takes a make more generalized module that will fit other needs beside their own.


I'm a bit surprised after clicking the title of the post to come here that the 36 lines of code are not anywhere on the page :)

Ted Bowman's picture

Well the code is in the video and the attachment.

Yeah sorry, I didn't initially see the attachment.

I skip videos due to the time it takes to get the info compared to reading :)

Ted Bowman's picture

Thank for the feedback. I have added link to the zip file in the middle of the article.

What is the purpose of the limit? Limit pwd guesses? If so, there's a small error in the validator, where user_authenticate is checked before the number of attempts and the user is not logged out, but _redirected_ to the logout page. Such a redirect doesn't have to be followed by the client.

Best to partiallly copy user_logout into your module, then call that.

Other Services

Drupal Consulting

Need help with project Planning?

Are you lost trying to select modules to implement your sites functionality?

Looking to simplify your Drupal development and solve problems faster?

Are you having trouble with modules such as Views or Panels?

Six Mile Tech’s Drupal consulting provides you or your company with an experienced Drupal expert.  You will be able to eliminate hours or days of wasted time looking for a way to solve your problem in Drupal. We can get you past your current dead ends in Drupal and we can teach you to solve your problems in Drupal the right way.

Contact Us to today to Learn More

Project Mentoring

Our mentoring service provides you with guidance through all of the phases of your Drupal project from planning to deployment.  We can help make sure that you are making your Drupal website the right way from the start.  With our guidance you will avoid common costly mistakes and start making more for your time.

Contact Us to today to Learn More


Training Newsletter

Sign up for our Training Newsletter to hear about in person and online trainings as well as to receive exclusive discount codes.

Online Trainings

Six Mile Tech offers online trainings via Skype, Google Hangout, or a screen sharing technology of your choice. These trainings can be used for generalized Drupal trainings or to tackle a specific problem for a site you are working on.