|
1 | 1 | <?php |
2 | 2 | /** |
| 3 | + * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> |
3 | 4 | * @copyright Copyright (c) 2016, ownCloud, Inc. |
4 | 5 | * |
5 | 6 | * @author Christoph Wurst <christoph@owncloud.com> |
|
31 | 32 | use OC_App; |
32 | 33 | use OC_Util; |
33 | 34 | use OCP\AppFramework\Controller; |
| 35 | +use OCP\AppFramework\Http; |
| 36 | +use OCP\AppFramework\Http\DataResponse; |
34 | 37 | use OCP\AppFramework\Http\RedirectResponse; |
35 | 38 | use OCP\AppFramework\Http\TemplateResponse; |
36 | 39 | use OCP\Authentication\TwoFactorAuth\IProvider; |
@@ -242,6 +245,8 @@ public function tryLogin($user, $password, $redirect_url, $remember_login = fals |
242 | 245 | // User has successfully logged in, now remove the password reset link, when it is available |
243 | 246 | $this->config->deleteUserValue($loginResult->getUID(), 'core', 'lostpassword'); |
244 | 247 |
|
| 248 | + $this->session->set('last-password-confirm', $loginResult->getLastLogin()); |
| 249 | + |
245 | 250 | if ($this->twoFactorManager->isTwoFactorAuthenticated($loginResult)) { |
246 | 251 | $this->twoFactorManager->prepareTwoFactorLogin($loginResult, $remember_login); |
247 | 252 |
|
@@ -273,4 +278,36 @@ public function tryLogin($user, $password, $redirect_url, $remember_login = fals |
273 | 278 | return $this->generateRedirect($redirect_url); |
274 | 279 | } |
275 | 280 |
|
| 281 | + /** |
| 282 | + * @NoAdminRequired |
| 283 | + * @UseSession |
| 284 | + * |
| 285 | + * @license GNU AGPL version 3 or any later version |
| 286 | + * |
| 287 | + * @param string $password |
| 288 | + * @return DataResponse |
| 289 | + */ |
| 290 | + public function confirmPassword($password) { |
| 291 | + $currentDelay = $this->throttler->getDelay($this->request->getRemoteAddress()); |
| 292 | + $this->throttler->sleepDelay($this->request->getRemoteAddress()); |
| 293 | + |
| 294 | + $user = $this->userSession->getUser(); |
| 295 | + if (!$user instanceof IUser) { |
| 296 | + return new DataResponse([], Http::STATUS_UNAUTHORIZED); |
| 297 | + } |
| 298 | + |
| 299 | + $loginResult = $this->userManager->checkPassword($user->getUID(), $password); |
| 300 | + if ($loginResult === false) { |
| 301 | + $this->throttler->registerAttempt('sudo', $this->request->getRemoteAddress(), ['user' => $user->getUID()]); |
| 302 | + if ($currentDelay === 0) { |
| 303 | + $this->throttler->sleepDelay($this->request->getRemoteAddress()); |
| 304 | + } |
| 305 | + |
| 306 | + return new DataResponse([], Http::STATUS_FORBIDDEN); |
| 307 | + } |
| 308 | + |
| 309 | + $confirmTimestamp = time(); |
| 310 | + $this->session->set('last-password-confirm', $confirmTimestamp); |
| 311 | + return new DataResponse(['lastLogin' => $confirmTimestamp], Http::STATUS_OK); |
| 312 | + } |
276 | 313 | } |
0 commit comments