Szukam i nie mogę znaleźć fragmentu koduzaimplementowany w celu sprawdzenia hasła podanego przez użytkownika podczas rejestracji. To jest kod, który sprawdza, czy jest poprawna liczba znaków...wiele cyfr i wiele symboli...itd.
Wierzę, że ta funkcja jest zaimplementowana od wersji joomla 3.0, moja wersja to joomla 3.2
Chciałbym "skopiować" ten kod do jednego z moich osobistych skryptów joomla.
Szukałem w kontrolerach i modelach "com_users" oraz we wtyczce "users" bez powodzenia.
Przestudiowałem również metodę bind() i save() klasy JUser, ale nic nie znalazłem.
Czy ktoś wie gdzie ten kod? Oszczędziłbym cenny czas.
Odpowiedzi:
0 dla odpowiedzi № 1Jest w 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>
I w libraries
teczka : 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 . " />";
}
Myślę, że tego chcesz.
Jeśli zgubiłeś się w Joomla Jforms, użyj wtyczka sprawdzania poprawności jquery. Jego dokumentacja.
0 dla odpowiedzi nr 2
Możesz stworzyć wtyczkę, która sprawdza poprawność hasła i zwraca true jako 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;
}
}