【问题标题】:Looking for the Joomla password checking寻找 Joomla 密码检查
【发布时间】:2014-04-20 02:04:33
【问题描述】:

我搜索并找不到用于检查用户在注册期间提供的密码的代码。那是检查是否有正确数量的字符的代码。 ..许多数字和许多符号......等等。

我相信是从joomla 3.0开始实现的这个功能,我的版本是joomla 3.2

我想为我的一个 joomla 个人脚本“复制”这段代码。

我在“com_users”的控制器和模型中搜索,在插件“users”中没有成功。

我还研究了 JUser 类的 bind() 方法和 save() 方法,但一无所获。

有谁知道这段代码在哪里?我会节省宝贵的时间。

【问题讨论】:

    标签: joomla passwords registration


    【解决方案1】:

    您可以创建插件来检查密码是否有效并返回 true 为是;

    <?php
    
    defined('_JEXEC') or die ;
    
    class plgUserHookbizz extends JPlugin {
    
     function onUserBeforeSave($user,$options)
     {
           $app = JFactory::getApplication();
           // Joomla session parameters
           $userId   = $user['id'];
           $name     = $user['name'];
           $password     = $user['password'];
           $username = $user['username'];
           $email    = $user['email'];
    
    
           if($this->validate($password)){
            return true;
           }else{
            $app->enqueueMessage('Please enter a valid password');
            return false;
           }
     }
    
     function validate($password){
       //Your validation here
       //Return true if valid
       return true;
    
     }
    

    }

    【讨论】:

      【解决方案2】:

      它在 jform 中:components/com_users/models/forms/registration.xml

      <?xml version="1.0" encoding="utf-8"?>
      <form>
          <fieldset name="default"
              label="COM_USERS_REGISTRATION_DEFAULT_LABEL"
          >
                  <!-- STUFF HERE -->    
      
              <field name="password2" type="password"
                  autocomplete="off"
                  class="validate-password"
                  description="COM_USERS_DESIRED_PASSWORD"
                  field="password1"
                  filter="raw"
                  label="COM_USERS_PROFILE_PASSWORD1_LABEL"
                  message="COM_USERS_PROFILE_PASSWORD1_MESSAGE"
                  size="30"
                  validate="equals"
                  required="true"
              />
      
              <field name="password1" type="password"
                  autocomplete="off"
                  class="validate-password"
                  description="COM_USERS_PROFILE_PASSWORD2_DESC"
                  filter="raw"
                  label="COM_USERS_PROFILE_PASSWORD2_LABEL"
                  size="30"
                  validate="password"
                  required="true"
              />
      
                  <!-- OTHER STUFF THERE -->
      
          </fieldset>
      </form>
      

      libraries 文件夹中:libraries/joomla/form/fields/password.php

      /**
           * Method to attach a JForm object to the field.
           *
           * @param   SimpleXMLElement  $element  The SimpleXMLElement object representing the <field /> tag for the form field object.
           * @param   mixed             $value    The form field value to validate.
           * @param   string            $group    The field name group control value. This acts as as an array container for the field.
           *                                      For example if the field has name="foo" and the group value is set to "bar" then the
           *                                      full field name would end up being "bar[foo]".
           *
           * @return  boolean  True on success.
           *
           * @see     JFormField::setup()
           * @since   3.2
           */
          public function setup(SimpleXMLElement $element, $value, $group = null)
          {
              $return = parent::setup($element, $value, $group);
      
              if ($return)
              {
                  $this->maxLength = $this->element['maxlength'] ? (int) $this->element['maxlength'] : 99;
                  $this->threshold = $this->element['threshold'] ? (int) $this->element['threshold'] : 66;
      
                  $meter       = (string) $this->element['strengthmeter'];
                  $this->meter = ($meter == 'true' || $meter == 'on' || $meter == '1');
              }
      
              return $return;
          }
      
          /**
           * Method to get the field input markup for password.
           *
           * @return  string  The field input markup.
           *
           * @since   11.1
           */
          protected function getInput()
          {
              // Translate placeholder text
              $hint = $this->translateHint ? JText::_($this->hint) : $this->hint;
      
              // Initialize some field attributes.
              $size         = !empty($this->size) ? ' size="' . $this->size . '"' : '';
              $maxLength    = !empty($this->maxLength) ? ' maxlength="' . $this->maxLength . '"' : '';
              $class        = !empty($this->class) ? ' class="' . $this->class . '"' : '';
              $readonly     = $this->readonly ? ' readonly' : '';
              $disabled     = $this->disabled ? ' disabled' : '';
              $required     = $this->required ? ' required aria-required="true"' : '';
              $hint         = $hint ? ' placeholder="' . $hint . '"' : '';
              $autocomplete = !$this->autocomplete ? ' autocomplete="off"' : '';
              $autofocus    = $this->autofocus ? ' autofocus' : '';
      
              if ($this->meter)
              {
                  JHtml::_('script', 'system/passwordstrength.js', true, true);
                  $script = 'new Form.PasswordStrength("' . $this->id . '",
                      {
                          threshold: ' . $this->threshold . ',
                          onUpdate: function(element, strength, threshold) {
                              element.set("data-passwordstrength", strength);
                          }
                      }
                  );';
      
                  // Load script on document load.
                  JFactory::getDocument()->addScriptDeclaration(
                      "jQuery(document).ready(function(){" . $script . "});"
                  );
              }
      
              // Including fallback code for HTML5 non supported browsers.
              JHtml::_('jquery.framework');
              JHtml::_('script', 'system/html5fallback.js', false, true);
      
              return '<input type="password" name="' . $this->name . '" id="' . $this->id . '"' .
                  ' value="' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . $hint . $autocomplete .
                  $class . $readonly . $disabled . $size . $maxLength . $required . $autofocus . ' />';
          }
      

      我想这就是你想要的。

      如果您对 Joomla Jforms 不了解,请使用 jquery validation plugin。它的documentation

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-05-12
        • 2014-02-13
        • 2018-05-19
        • 1970-01-01
        • 2012-11-20
        • 1970-01-01
        • 1970-01-01
        • 2017-01-01
        相关资源
        最近更新 更多