mirror of
https://github.com/getnamingo/registry.git
synced 2025-05-13 16:16:59 +02:00
Added ability to have password policy and password expiration
This commit is contained in:
parent
e0eeaed83c
commit
2620dfd7f3
5 changed files with 51 additions and 3 deletions
|
@ -69,7 +69,13 @@ class PasswordController extends Controller
|
|||
* @throws \Pinga\Auth\AuthError
|
||||
*/
|
||||
public function updatePassword(Request $request, Response $response){
|
||||
global $container;
|
||||
$data = $request->getParsedBody();
|
||||
$db = $container->get('db');
|
||||
$userId = $db->selectValue(
|
||||
'SELECT user_id FROM users_resets WHERE selector = ? AND expires > ? ORDER BY expires DESC LIMIT 1',
|
||||
[ $data['selector'], time() ]
|
||||
);
|
||||
$validation = $this->validator->validate($request, [
|
||||
'password' => v::notEmpty()->stringType()->length(8),
|
||||
'password2' => v::notEmpty(),
|
||||
|
@ -78,10 +84,13 @@ class PasswordController extends Controller
|
|||
if ($validation->failed()) {
|
||||
redirect()->route('update.password',[],['selector'=>urlencode($data['selector']),'token'=>urlencode($data['token'])]);
|
||||
}
|
||||
|
||||
elseif (!v::equals($data['password'])->validate($data['password2'])) {
|
||||
redirect()->route('update.password',[],['selector'=>urlencode($data['selector']),'token'=>urlencode($data['token'])])->with('error','The password do not match.');
|
||||
}
|
||||
if (!checkPasswordComplexity($data['password2'])) {
|
||||
redirect()->route('update.password',[],['selector'=>urlencode($data['selector']),'token'=>urlencode($data['token'])])->with('error','Password too weak. Use a stronger password.');
|
||||
}
|
||||
$_SESSION['password_last_changed'][$userId] = time();
|
||||
Auth::resetPasswordUpdate($data['selector'], $data['token'], $data['password']);
|
||||
}
|
||||
|
||||
|
@ -91,6 +100,7 @@ class PasswordController extends Controller
|
|||
* @throws \Pinga\Auth\AuthError
|
||||
*/
|
||||
public function changePassword(Request $request, Response $response){
|
||||
global $container;
|
||||
$data = $request->getParsedBody();
|
||||
$validation = $this->validator->validate($request, [
|
||||
'old_password' => v::notEmpty(),
|
||||
|
@ -99,6 +109,11 @@ class PasswordController extends Controller
|
|||
if ($validation->failed()) {
|
||||
redirect()->route('profile');
|
||||
}
|
||||
if (!checkPasswordComplexity($data['new_password'])) {
|
||||
redirect()->route('profile')->with('error','Password too weak. Use a stronger password.');
|
||||
}
|
||||
$userId = $container->get('auth')->user()['id'];
|
||||
$_SESSION['password_last_changed'][$userId] = time();
|
||||
Auth::changeCurrentPassword($data['old_password'], $data['new_password']);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue