Skip to content

Commit

Permalink
Changed: CP Password rules
Browse files Browse the repository at this point in the history
  • Loading branch information
bymayo committed Mar 28, 2024
1 parent b166884 commit d058383
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Porter Changelog

## 1.0.4 - 2024-03-28
### Fixed
- Blank errors appearing when matching password rules

### Added
- Passwords changed in the CP now go through the password rules

## 1.0.3 - 2022-08-23
### Added
- `porter.php` config file example.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "bymayo/porter",
"description": "A toolkit with lots of helpers for users and accounts",
"type": "craft-plugin",
"version": "1.0.3",
"version": "1.0.4",
"keywords": [
"craft",
"cms",
Expand Down
38 changes: 17 additions & 21 deletions src/Porter.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,36 +178,32 @@ function(RegisterEmailMessagesEvent $event) {
User::EVENT_BEFORE_VALIDATE,
function (ModelEvent $event) {

if (!Craft::$app->getRequest()->getIsCpRequest()) {
$user = $event->sender;

$user = $event->sender;
if ($this->settings->emailBurners && $this->settings->emailsBurnersVerifierApiKey)
{

if ($this->settings->emailBurners)
{

$errors = $this->emailPassword->checkBurnerEmail($user->email);
$errors = $this->emailPassword->checkBurnerEmail($user->email);

foreach ($errors as $error) {
$user->addError('email', $error);
}

foreach ($errors as $error) {
$user->addError('email', $error);
}

}

if ($this->settings->passwordForcePolicy && ($user->newPassword || strlen($user->newPassword) >= 0))
{

$errors = $this->emailPassword->checkPasswordPolicy($user->newPassword);
if ($this->settings->passwordForcePolicy && ($user->newPassword || strlen($user->newPassword) >= 0))
{

if ($errors)
{
$errors = $this->emailPassword->checkPasswordPolicy($user->newPassword);

$event->isValid = 0;
if ($errors)
{

foreach ($errors as $error) {
$user->addError('newPassword', $error);
}
$event->isValid = 0;

}
foreach ($errors as $error) {
$user->addError('newPassword', $error);
}

}

Expand Down
8 changes: 4 additions & 4 deletions src/services/EmailPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ public function checkPasswordPolicy($password)
{
switch ($rule) {
case 'lowercase':
$errors[] = $this->containsLowercase($password);
is_null($this->containsLowercase($password)) ?: $errors[] = $this->containsLowercase($password);
break;
case 'uppercase':
$errors[] = $this->containsUppercase($password);
is_null($this->containsUppercase($password)) ?: $errors[] = $this->containsUppercase($password);
break;
case 'numeric':
$errors[] = $this->containsNumeric($password);
is_null($this->containsNumeric($password)) ?: $errors[] = $this->containsNumeric($password);
break;
case 'symbol':
$errors[] = $this->containsSymbol($password);
is_null($this->containsSymbol($password)) ?: $errors[] = $this->containsSymbol($password);
break;
}
}
Expand Down

0 comments on commit d058383

Please sign in to comment.