Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
prlp
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
10
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
prlp
Commits
082f5e7d
Commit
082f5e7d
authored
7 years ago
by
Jitesh Doshi
Browse files
Options
Downloads
Patches
Plain Diff
Improved hash validation and better UX.
parent
3e0cbf3f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
prlp.module
+13
-4
13 additions, 4 deletions
prlp.module
src/Controller/PrlpController.php
+8
-1
8 additions, 1 deletion
src/Controller/PrlpController.php
with
21 additions
and
5 deletions
prlp.module
+
13
−
4
View file @
082f5e7d
...
...
@@ -6,6 +6,8 @@
*/
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Component\Utility\Crypt
;
use
Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
;
/**
* Default value of the 'prlp_destination' config varible.
...
...
@@ -25,8 +27,15 @@ function prlp_form_user_pass_reset_alter(&$form, FormStateInterface $form_state,
}
function
prlp_form_user_pass_reset_submit
(
&
$form
,
FormStateInterface
$form_state
)
{
$account
=
$form_state
->
getBuildInfo
()[
'args'
][
0
];
$account
->
setPassword
(
$form_state
->
getValue
(
'pass'
));
$account
->
save
();
drupal_set_message
(
t
(
'Your new password has been saved.'
));
$args
=
$form_state
->
getBuildInfo
()[
'args'
];
list
(
$user
,
$expiration
,
$timestamp
,
$hash
)
=
$args
;
// save the new password ONLY if the user and the hash are valid
if
(
$user
!==
NULL
&&
$user
->
isActive
()
&&
Crypt
::
hashEquals
(
$hash
,
user_pass_rehash
(
$user
,
$timestamp
)))
{
$user
->
setPassword
(
$form_state
->
getValue
(
'pass'
));
$user
->
save
();
drupal_set_message
(
t
(
'Your new password has been saved.'
));
// set this request attribute so that we don't fail on hash check
// in PrlpController::prlpResetPassLogin()
Drupal
::
request
()
->
getSession
()
->
set
(
'prlp_skip_hash_check'
,
TRUE
);
}
}
This diff is collapsed.
Click to expand it.
src/Controller/PrlpController.php
+
8
−
1
View file @
082f5e7d
...
...
@@ -2,6 +2,7 @@
namespace
Drupal\prlp\Controller
;
use
Drupal
;
use
Drupal\Component\Utility\Crypt
;
use
Drupal\Core\Form\FormState
;
use
Drupal\user\Controller\UserController
;
...
...
@@ -36,8 +37,14 @@ class PrlpController extends UserController {
/** @var \Drupal\user\UserInterface $user */
$user
=
$this
->
userStorage
->
load
(
$uid
);
// Check if the hash is valid, but not if you were told by prlp to
// skip checking it.
$check_hash
=
!
Drupal
::
request
()
->
getSession
()
->
get
(
'prlp_skip_hash_check'
);
// remove this session setting immediately to avoid security holes
!
Drupal
::
request
()
->
getSession
()
->
remove
(
'prlp_skip_hash_check'
);
$invalid_hash
=
$check_hash
&&
!
Crypt
::
hashEquals
(
$hash
,
user_pass_rehash
(
$user
,
$timestamp
));
// Verify that the user exists and is active.
if
(
$user
===
NULL
||
!
$user
->
isActive
())
{
if
(
$user
===
NULL
||
!
$user
->
isActive
()
||
$invalid_hash
)
{
// Blocked or invalid user ID, so deny access. The parameters will be in
// the watchdog's URL for the administrator to check.
throw
new
AccessDeniedHttpException
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment