寻找Joomla密码检查

时间:2014-03-14 16:33:05

标签: joomla passwords registration

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

我相信这个功能是自joomla 3.0以来实现的,我的版本是joomla 3.2

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

我搜索了“com_users”的控制器和模型,以及插件“用户”中没有成功。

我还研究了类JUser的bind()方法和save()方法,但我什么也没找到。

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

2 个答案:

答案 0 :(得分:0)

它位于jformcomponents/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

答案 1 :(得分:0)

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

<?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;

 }

}