-
-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added valid_password method in ValidationRules #227
Closed
najdanovicivan
wants to merge
1
commit into
lonnieezell:develop
from
najdanovicivan:password-validator
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,9 +161,7 @@ public function validate(array $credentials, bool $returnUser=false) | |
} | ||
|
||
// Now, try matching the passwords. | ||
$result = password_verify(base64_encode( | ||
hash('sha384', $password, true) | ||
), $user->password_hash); | ||
$result = $this->validate_password($user, $password); | ||
|
||
if (! $result) | ||
{ | ||
|
@@ -186,4 +184,23 @@ public function validate(array $credentials, bool $returnUser=false) | |
: true; | ||
} | ||
|
||
/** | ||
* Validates the user password | ||
* | ||
* @param User $user | ||
* @param string $password | ||
* | ||
* @return bool | ||
*/ | ||
public function validate_password(User $user, string $password) : bool | ||
{ | ||
// Can't validate without a password. | ||
if (empty($credentials['password']) || count($credentials) < 2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a few problems here:
|
||
{ | ||
return password_verify(base64_encode( | ||
hash('sha384', $password, true) | ||
), $user->password_hash); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -60,6 +60,27 @@ public function strong_password(string $value, string &$error1 = null, array $da | |||||
return $result; | ||||||
} | ||||||
|
||||||
/** | ||||||
* A validation helper method to check if the passed | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* current user's password is valid | ||||||
* | ||||||
* @param string $password | ||||||
* | ||||||
* @return bool | ||||||
*/ | ||||||
public function valid_password(string $password) | ||||||
{ | ||||||
helper('auth'); | ||||||
$user = user(); | ||||||
|
||||||
if (empty($user)) { | ||||||
return false; | ||||||
} | ||||||
|
||||||
$authenticate = \Config\Services::authentication(); | ||||||
return $authenticate->validate_password($user, $password); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Builds a new user instance from the global request. | ||||||
* | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
return [ | ||
'valid_password' => 'The {field} is not valid.', | ||
]; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically all method names are camel-cased unless used for validation rules.