/** * @param $password * * @return string * @throws PasswordConstraintsException */ public function encrypt($password) { if (PasswordConstraintsService::singleton()->validate($password)) { $salt = helpers_Random::generateString($this->saltLength); return $salt . hash($this->algorithm, $salt . $password); } throw new PasswordConstraintsException(__('Password must be: %s', implode(',', PasswordConstraintsService::singleton()->getErrors()))); }
/** * Short description of method evaluate * * @access public * @param values * @return boolean */ public function evaluate($values) { $returnValue = PasswordConstraintsService::singleton()->validate($values); if (!$returnValue && !$this->hasOption('message')) { $this->setMessage(implode(', ', PasswordConstraintsService::singleton()->getErrors())); } return (bool) $returnValue; }
/** * @return common_configuration_Report */ public function check() { $content = json_decode(file_get_contents('php://input'), true); if (PasswordConstraintsService::singleton()->validate($content['value']['password'])) { $report = new common_configuration_Report(common_configuration_Report::VALID, 'Password is strong enough', $this); } else { $report = new common_configuration_Report(common_configuration_Report::INVALID, implode("</br>", PasswordConstraintsService::singleton()->getErrors()), $this); } return $report; }
/** * Initialiaze password reset form elements * * @access public * @author Aleh Hutnikau <*****@*****.**> * @return mixed */ public function initElements() { $tokenElement = tao_helpers_form_FormFactory::getElement('token', 'Hidden'); $this->form->addElement($tokenElement); $pass1Element = tao_helpers_form_FormFactory::getElement('newpassword', 'Hiddenbox'); $pass1Element->setDescription(__('New password')); $pass1Element->addValidators(PasswordConstraintsService::singleton()->getValidators()); $pass1Element->setBreakOnFirstError(false); $this->form->addElement($pass1Element); $pass2Element = tao_helpers_form_FormFactory::getElement('newpassword2', 'Hiddenbox'); $pass2Element->setDescription(__('Repeat new password')); $pass2Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('Password', array('password2_ref' => $pass1Element)))); $this->form->addElement($pass2Element); }
/** * Short description of method initElements * * @access public * @author Joel Bout, <*****@*****.**> */ public function initElements() { $pass1Element = tao_helpers_form_FormFactory::getElement('oldpassword', 'Hiddenbox'); $pass1Element->setDescription(__('Old Password')); $pass1Element->addValidator(tao_helpers_form_FormFactory::getValidator('Callback', array('message' => __('Passwords are not matching'), 'object' => tao_models_classes_UserService::singleton(), 'method' => 'isPasswordValid', 'param' => tao_models_classes_UserService::singleton()->getCurrentUser()))); $this->form->addElement($pass1Element); $pass2Element = tao_helpers_form_FormFactory::getElement('newpassword', 'Hiddenbox'); $pass2Element->setDescription(__('New password')); $pass2Element->addValidators(PasswordConstraintsService::singleton()->getValidators()); $pass2Element->setBreakOnFirstError(false); $this->form->addElement($pass2Element); $pass3Element = tao_helpers_form_FormFactory::getElement('newpassword2', 'Hiddenbox'); $pass3Element->setDescription(__('Repeat new password')); $pass3Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('Password', array('password2_ref' => $pass2Element)))); $this->form->addElement($pass3Element); }
protected function buildInvalidPassword() { $constaintsService = PasswordConstraintsService::singleton(); $config = $this->invokeProtectedMethod($constaintsService, 'getConfig'); $invalidPassword = $this->buildValidPassword(); if ($config['upper'] === true) { $invalidPassword = str_replace('A', '', $invalidPassword); } if ($config['lower'] === true) { $invalidPassword = str_replace('b', '', $invalidPassword); } if ($config['number'] === true) { $invalidPassword = str_replace('3', '', $invalidPassword); } if ($config['spec'] === true) { $invalidPassword = str_replace('@', '', $invalidPassword); } $invalidPassword = substr($invalidPassword, 0, $config['length'] - 1); return $invalidPassword; }
/** * Short description of method initElements * * @access protected * @author Joel Bout, <*****@*****.**> */ protected function initElements() { if (!isset($this->options['mode'])) { throw new Exception("Please set a mode into container options "); } parent::initElements(); //login field $loginElement = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_USER_LOGIN)); $loginElement->setDescription($loginElement->getDescription() . ' *'); if ($this->options['mode'] === 'add') { $loginElement->addValidators(array(tao_helpers_form_FormFactory::getValidator('NotEmpty'), tao_helpers_form_FormFactory::getValidator('Callback', array('object' => tao_models_classes_UserService::singleton(), 'method' => 'loginAvailable', 'message' => __('This Login is already in use'))))); } else { $loginElement->setAttributes(array('readonly' => 'readonly', 'disabled' => 'disabled')); } //set default lang to the languages fields $langService = tao_models_classes_LanguageService::singleton(); $dataLangElt = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_USER_DEFLG)); $dataLangElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); $dataLangElt->setDescription($dataLangElt->getDescription() . ' *'); $dataUsage = new core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_DATA); $dataOptions = array(); foreach ($langService->getAvailableLanguagesByUsage($dataUsage) as $lang) { $dataOptions[tao_helpers_Uri::encode($lang->getUri())] = $lang->getLabel(); } $dataLangElt->setOptions($dataOptions); $uiLangElt = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_USER_UILG)); $uiLangElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); $uiLangElt->setDescription($uiLangElt->getDescription() . ' *'); $guiUsage = new core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_GUI); $guiOptions = array(); foreach ($langService->getAvailableLanguagesByUsage($guiUsage) as $lang) { $guiOptions[tao_helpers_Uri::encode($lang->getUri())] = $lang->getLabel(); } $uiLangElt->setOptions($guiOptions); // roles field $property = new core_kernel_classes_Property(PROPERTY_USER_ROLES); $roles = $property->getRange()->getInstances(true); $rolesOptions = array(); foreach ($roles as $r) { $rolesOptions[tao_helpers_Uri::encode($r->getUri())] = $r->getLabel(); } asort($rolesOptions); $rolesElt = $this->form->getElement(tao_helpers_Uri::encode($property->getUri())); $rolesElt->setDescription($rolesElt->getDescription() . ' *'); $rolesElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); $rolesElt->setOptions($rolesOptions); // password field $this->form->removeElement(tao_helpers_Uri::encode(PROPERTY_USER_PASSWORD)); if ($this->options['mode'] === 'add') { $pass1Element = tao_helpers_form_FormFactory::getElement('password1', 'Hiddenbox'); $pass1Element->setDescription(__('Password *')); $pass1Element->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); $pass1Element->addValidators(PasswordConstraintsService::singleton()->getValidators()); $pass1Element->setBreakOnFirstError(false); $this->form->addElement($pass1Element); $pass2Element = tao_helpers_form_FormFactory::getElement('password2', 'Hiddenbox'); $pass2Element->setDescription(__('Repeat password *')); $pass2Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('NotEmpty'), tao_helpers_form_FormFactory::getValidator('Password', array('password2_ref' => $pass1Element)))); $this->form->addElement($pass2Element); } else { if (helpers_PlatformInstance::isDemo()) { $warning = tao_helpers_form_FormFactory::getElement('warningpass', 'Label'); $warning->setValue(__('Unable to change passwords in demo mode')); $this->form->addElement($warning); $this->form->createGroup("pass_group", __("Change the password"), array('warningpass')); } else { $pass2Element = tao_helpers_form_FormFactory::getElement('password2', 'Hiddenbox'); $pass2Element->setDescription(__('New password')); $pass2Element->addValidators(PasswordConstraintsService::singleton()->getValidators()); $pass2Element->setBreakOnFirstError(false); $this->form->addElement($pass2Element); $pass3Element = tao_helpers_form_FormFactory::getElement('password3', 'Hiddenbox'); $pass3Element->setDescription(__('Repeat new password')); $pass3Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('Password', array('password2_ref' => $pass2Element)))); $this->form->addElement($pass3Element); $this->form->createGroup("pass_group", __("Change the password"), array('password1', 'password2', 'password3')); if (empty($_POST[$pass2Element->getName()]) && empty($_POST[$pass3Element->getName()])) { $pass2Element->setForcedValid(); $pass3Element->setForcedValid(); } } } }
public static function tearDownAfterClass() { $register = self::getMethod('register'); $config = self::getMethod('getConfig')->invokeArgs(PasswordConstraintsService::singleton(), array()); $register->invokeArgs(PasswordConstraintsService::singleton(), array($config)); }