You are here

function protected_pages_enter_password_validate in Protected Pages 7.2

Same name and namespace in other branches
  1. 7 protected_pages.inc \protected_pages_enter_password_validate()

Implements hook_validate().

File

./protected_pages.inc, line 57
Provides page callbacks for enter password page.

Code

function protected_pages_enter_password_validate($form, &$form_state) {
  $password = sha1(trim(check_plain($form_state['values']['password'])));
  $global_password_setting = variable_get('protected_pages_user_global_password', 'per_page_or_global');
  if ($global_password_setting == 'per_page_password') {
    $pid = db_select('protected_pages')
      ->fields('protected_pages', array(
      'pid',
    ))
      ->condition('password', $password)
      ->condition('pid', $form_state['values']['protected_page_pid'])
      ->range(0, 1)
      ->execute()
      ->fetchField();
    if (!$pid) {
      form_set_error('password', variable_get('protected_pages_incorrect_password_msg', t('Incorrect password!')));
    }
  }
  elseif ($global_password_setting == 'per_page_or_global') {
    $pid = db_select('protected_pages')
      ->fields('protected_pages', array(
      'pid',
    ))
      ->condition('password', $password)
      ->condition('pid', $form_state['values']['protected_page_pid'])
      ->range(0, 1)
      ->execute()
      ->fetchField();
    $global_password = variable_get('protected_pages_global_password', '');
    if (!$pid && $global_password != $password) {
      form_set_error('password', variable_get('protected_pages_incorrect_password_msg', t('Incorrect password!')));
    }
  }
  else {
    $global_password = variable_get('protected_pages_global_password', '');
    if ($global_password != $password) {
      form_set_error('password', variable_get('protected_pages_incorrect_password_msg', t('Incorrect password!')));
    }
  }
}