diff --git a/protected_node.module b/protected_node.module
index 44c565f..d7f7a4e 100644
--- a/protected_node.module
+++ b/protected_node.module
@@ -467,6 +467,10 @@ function protected_node_node_validate($node, $form, &$form_state) {
     return;
   }
 
+  global $_protected_node_emails;
+  global $_protected_node_random_passwd;
+  $_protected_node_emails = '';
+  $_protected_node_random_passwd = '';
   if ($node->protected_node_is_protected && (user_access('edit any protected node password') || user_access('edit ' . $node->type . ' password'))) {
     $missing_password = FALSE;
     if (empty($node->protected_node_passwd)) {
@@ -512,6 +516,9 @@ function protected_node_node_validate($node, $form, &$form_state) {
         }
         $_protected_node_emails = implode(', ', $emails);
         if ($_protected_node_emails && $missing_password && variable_get('protected_node_random_password', FALSE)) {
+          // Automatically generate a password for the email. Note that means
+          // the author won't know the password!
+          $_protected_node_random_passwd = user_password();
           // Not missing anymore.
           $missing_password = FALSE;
           drupal_set_message(t('A random password was generated in order to send the email about this page. Remember that changing the password will prevent users you just emailed from accessing this page.'), 'warning');
diff --git a/protected_node.settings.inc b/protected_node.settings.inc
index 7f47d5f..537b44d 100644
--- a/protected_node.settings.inc
+++ b/protected_node.settings.inc
@@ -455,7 +455,7 @@ function protected_node_admin_settings() {
     '#type' => 'checkbox',
     '#title' => t('Enable protected node email support'),
     '#default_value' => variable_get('protected_node_email_activation', FALSE),
-    '#description' => t('Check this box to enable the protected node email support'),
+    '#description' => t('Check this box to enable the protected node email support (NOTE: Random password support available as part of this feature).'),
   );
 
   $form['protected_node_auto_email']['protected_node_email_box_width'] = array(
@@ -464,6 +464,11 @@ function protected_node_admin_settings() {
     '#size' => 10,
     '#default_value' => variable_get('protected_node_email_box_width', '10'),
     '#description' => t('Enter the width (number of columns) of the email box text area. Must be a positive integer. Default value : 10.'),
+    '#states' => array(
+      'visible' => array(
+       ':input[name="protected_node_email_activation"]' => array('checked' => TRUE),
+      ),
+    ),
   );
 
   $form['protected_node_auto_email']['protected_node_email_box_height'] = array(
@@ -472,6 +477,11 @@ function protected_node_admin_settings() {
     '#size' => 10,
     '#default_value' => variable_get('protected_node_email_box_height', '2'),
     '#description' => t('Enter the height (number of rows) of the email box text area. Must be a positive integer. Default value : 2.'),
+    '#states' => array(
+      'visible' => array(
+       ':input[name="protected_node_email_activation"]' => array('checked' => TRUE),
+      ),
+    ),
   );
 
   $form['protected_node_auto_email']['protected_node_email_from'] = array(
@@ -479,6 +489,11 @@ function protected_node_admin_settings() {
     '#title' => t('From email address'),
     '#default_value' => variable_get('protected_node_email_from', ''),
     '#description' => t('Enter the email address used in the From: header. By default, [site-mail] is used (@mail)', array('@mail' => variable_get('site_mail', '<undefined>'))),
+    '#states' => array(
+      'visible' => array(
+       ':input[name="protected_node_email_activation"]' => array('checked' => TRUE),
+      ),
+    ),
   );
 
   $form['protected_node_auto_email']['protected_node_email_subject'] = array(
@@ -486,6 +501,11 @@ function protected_node_admin_settings() {
     '#title' => t('Email subject'),
     '#default_value' => variable_get('protected_node_email_subject', protected_node_email_subject()),
     '#description' => t('Enter the subject of the email. You may enter tokens in this field. Remember that [user-name] will be the author name.'),
+    '#states' => array(
+      'visible' => array(
+       ':input[name="protected_node_email_activation"]' => array('checked' => TRUE),
+      ),
+    ),
   );
 
   $form['protected_node_auto_email']['protected_node_email_body'] = array(
@@ -494,6 +514,11 @@ function protected_node_admin_settings() {
     '#rows' => 15,
     '#default_value' => variable_get('protected_node_email_body', protected_node_email_body()),
     '#description' => t('Enter the body of the email. You may enter tokens in this field. Remember that [user-name] will be the author name.'),
+    '#states' => array(
+      'visible' => array(
+       ':input[name="protected_node_email_activation"]' => array('checked' => TRUE),
+      ),
+    ),
   );
 
   $form['protected_node_auto_email']['protected_node_random_password'] = array(
@@ -501,6 +526,11 @@ function protected_node_admin_settings() {
     '#title' => t('Generate a random password if necessary'),
     '#default_value' => variable_get('protected_node_random_password', FALSE),
     '#description' => t('When this flag is set, saving a protected node without re-entering the password will randomize a password and send it to your users. You may enter your email address to know about the password yourself. (It otherwise gets encrypted in the database.)'),
+    '#states' => array(
+      'visible' => array(
+       ':input[name="protected_node_email_activation"]' => array('checked' => TRUE),
+      ),
+    ),
   );
 
   $form['protected_node_form'] = array(
diff --git a/tests/protected_node.mail_test.test b/tests/protected_node.mail_test.test
index ffad6bc..41c84a5 100644
--- a/tests/protected_node.mail_test.test
+++ b/tests/protected_node.mail_test.test
@@ -33,6 +33,7 @@ class ProtectedNodeMail extends ProtectedNodeBaseTestCase {
     $protected_node_settings = array(
       'protected_node_use_global_password' => PROTECTED_NODE_PER_NODE_PASSWORD,
       'protected_node_email_activation' => 1,
+      'protected_node_random_password' => 1,
     );
     $this->drupalPost('admin/config/content/protected_node', $protected_node_settings, t('Save configuration'));
   }
@@ -62,6 +63,25 @@ class ProtectedNodeMail extends ProtectedNodeBaseTestCase {
   }
 
   /**
+   * Test that a random password is created and saved.
+   */
+  public function testRandomPwSaved() {
+    // Log in as Admin.
+    $this->drupalLogin($this->adminUser);
+    // Don't set a password.
+    $password = '';
+    // To parameter.
+    $to = 'example@example.com';
+    // Create a new page node.
+    $node = $this->createProtectedNode($password, $to);
+    // Once the node created logout the User.
+    $this->drupalLogout();
+
+    $pw = $node->protected_node_passwd;
+    $this->assertTrue(!empty($pw), "Generated password exists.");
+  }
+
+  /**
    * Helper method to create a protected node.
    *
    * Please make sure the user has the permission to create the node before
