-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Standardize password hash function usage #9480
Conversation
As preparation for introduction of a stronger hash function in matomo-org#5728, this standardizes the usage of the current **password** hash function across the Login and UsersManager plugins. Specifically: * Use UsersManager::getPasswordHash() throughout, instead of previous direct use of md5() in some places * Concentrate the hash length sanity check in the newly created UsersManager::checkPasswordHash(). Previously, UsersManager\Auth and Login\PasswordResetter classes did it separately. Both checks were moved into the newly created UsersManager class function, as that is also where other public static password check functions reside. * Replaced the "md5" string with "hash" in affected variable names and comments No functional change is intended.
As preparation for Common::hash() changing its hash function some time in future
For performance reasons
Does anyone know why the test fails? I've tested the patch with piwik-2.16.0-b1.zip (on a remote test server, updated from piwik-2.15.0-b14 via a complete delete and re-upload via FTP, keeping the DB tables) and don't get any errors with PHP 5.5. Tested:
I don't get any The only error I see does not seem to be related: UsersManager: When trying to change own password as the "view" user (not tested as super user), I get following error:
(Without trying to change the clock format. And similarly for But that error could be due to the update from the 2.15.0-b14 beta. I'd need to try updating from a released version some time. |
I found it, thanks to https://builds-artifacts.piwik.org/piwik/piwik/master/17449/ (missing semicolon in The remaining Please let me know if it'd be better to do this in the 3.0 branch, which #5728 is for (or not at all). |
* @return string | ||
*/ | ||
public function getTokenAuth($userLogin, $md5Password) | ||
public function getTokenAuth($userLogin, $passwordHash) |
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.
That's why tests fail as it breaks the API. Unfortunately we cannot rename this one although it would be good :(
Users call it eg with index.php?module=API&method=API.getTokenAuth&userLogin=foo&md5Password=bar...
. This would break all applications, libraries etc that use this method (eg the Piwik Mobile App but also many other libraries and apps).
Unfortunately we do not have a versioning in our API to handle such cases. The only thing that I could imagine would be making $md5Password
optional, add $passwordHash
optional and then checking in the method that at least one of them is set and if not throw an exception.
We'd need to document this in the developer changelog and deprecate $md5Password
parameter. We'd probably never actually remove that parameter instead deprecate the whole API and replace it with a REST API in a few years
PR looks good! Thx for that. Only one issue with the failing test. Explained it in a code comment |
Thanks for the feedback! I reverted the renaming (adding a comment in https://github.com/piwik/piwik/pull/9480/files#diff-243038712dace7532e3b1856dd63274eR786 instead) and fixed another issue left over. I don't know what the remaining test failures are about, though. E.g.:
As well as the moved text in the screenshots in https://builds-artifacts.piwik.org/piwik/piwik/master/17472/. I would appreciate any hints. |
Thx for the quick change! The failing test is not due to your change. I merged a couple of PRs yesterday but haven't fixed the build yet. |
Standardize password hash function usage
Reported in #9666. |
As preparation for introduction of a stronger password hash function in #5728, this standardizes the usage of the current password hash function across the Login and UsersManager plugins. Specifically:
UsersManager::getPasswordHash()
throughout, instead of previous direct use ofmd5()
in some places.UsersManager::checkPasswordHash()
. Previously,UsersManager\API
andLogin\PasswordResetter
classes did it separately. Both checks were moved into the newly created function in theUsersManager
class, as that is also where otherpublic static
password check functions reside.No functional change is intended.
One little caveat is that I can't test at the moment. It would be great if someone could take this on a test ride.To summarize the hash function uses by the Login and UsersManager plugins:
The password hash function is now centralized in (https://github.com/piwik/piwik/blob/c54fc9e4e6072e7bffbb1a02b1c11645c50038e4/plugins/UsersManager/UsersManager.php#L153):
Following hash function uses were not modified:
token_auth
hash function is controlled by (https://github.com/piwik/piwik/blob/c54fc9e4e6072e7bffbb1a02b1c11645c50038e4/plugins/UsersManager/API.php#L789) (apparently for DB storage - this could be something for Hashed and salted storage of token_auth #9457):As well as by (https://github.com/Joey3000/piwik/blob/c54fc9e4e6072e7bffbb1a02b1c11645c50038e4/plugins/Login/SessionInitializer.php#L235) (apparently for cookie setting - this could be changed, e.g, at the same time as Hashed and salted storage of token_auth #9457 gets implemented, to have
token_auth
only change once):Password reset token (per e-mail) is controlled by (https://github.com/piwik/piwik/blob/c54fc9e4e6072e7bffbb1a02b1c11645c50038e4/plugins/Login/PasswordResetter.php#L320):