Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"slim/twig-view": "^2.2",
"techwilk/twig-linewrap": "^1.0",
"techwilk/twig-slim-csrf": "^1.0",
"twig/extensions": "^1.4"
"twig/extensions": "^1.4",
"divineomega/password_exposed": "^2.3"
},
"autoload": {
"psr-4": {
Expand All @@ -65,4 +66,4 @@
"Tests\\": "tests/"
}
}
}
}
183 changes: 181 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions generated-classes/TechWilk/Rota/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace TechWilk\Rota;

use DateTime;
use DivineOmega\PasswordExposed\PasswordExposedChecker;
use DivineOmega\PasswordExposed\PasswordStatus;
use Exception;
use Propel\Runtime\ActiveQuery\Criteria;
use TechWilk\Rota\Authoriser\UserAuthoriser;
use TechWilk\Rota\Base\User as BaseUser;
Expand Down Expand Up @@ -68,10 +71,16 @@ public function setPassword($v)
$v = (string) $v;
}

$exposedChecker = new PasswordExposedChecker();

if ($exposedChecker->passwordExposed($v) === PasswordStatus::EXPOSED) {
throw new Exception('Password exposed in recent data breach.');
}

if (!password_verify($v, $this->password)) {
$bcrypt_options = [
'cost' => 12,
];
'cost' => 12,
];
$this->password = password_hash($v, PASSWORD_BCRYPT, $bcrypt_options);

$this->modifiedColumns[UserTableMap::COL_PASSWORD] = true;
Expand Down
11 changes: 9 additions & 2 deletions src/classes/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace TechWilk\Rota\Controller;

use Exception;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TechWilk\Rota\Crypt;
Expand Down Expand Up @@ -186,8 +187,14 @@ public function postUserPasswordChange(ServerRequestInterface $request, Response
return $this->view->render($response, 'user-password.twig', ['user' => $u, 'message' => $message]);
}

$u->setPassword($new);
$u->save();
try {
$u->setPassword($new);
$u->save();
} catch (Exception $e) {
$message = 'Password has been exposed in a recent data breach. For your safety, we check all passwords against data breaches from other organisations and prevent you from using passwords which have been leaked. If you use this password for any other account, we strongly advise you change it immediately.';

return $this->view->render($response, 'user-password.twig', ['user' => $u, 'message' => $message]);
}

return $response->withStatus(303)->withHeader('Location', $this->router->pathFor('user', ['id' => $u->getId()]));
}
Expand Down