Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/global.ini.php4
-rw-r--r--core/Common.php36
-rw-r--r--plugins/Login/Controller.php25
3 files changed, 63 insertions, 2 deletions
diff --git a/config/global.ini.php b/config/global.ini.php
index e382897e29..e79d53e5a1 100644
--- a/config/global.ini.php
+++ b/config/global.ini.php
@@ -139,6 +139,10 @@ minimum_memory_limit = 128
; This can be disabled, if for example you wish to import an existing User database in Piwik and your rules are less restrictive
disable_checks_usernames_attributes = 0
+; Piwik will use the configured hash algorithm where possible.
+; For legacy data, fallback or non-security scenarios, we use md5.
+hash_algorithm = whirlpool
+
; by default, Piwik uses relative URLs, so you can login using http:// or https://
; (the latter assumes you have a valid SSL certificate).
; If set to 1, Piwik redirects the login form to use a secure connection (i.e., https).
diff --git a/core/Common.php b/core/Common.php
index 30f2a976ec..b4ea9cf2c7 100644
--- a/core/Common.php
+++ b/core/Common.php
@@ -802,6 +802,42 @@ class Piwik_Common
}
/**
+ * Configureable hash() algorithm (defaults to md5)
+ *
+ * @param string $str String to be hashed
+ * @param bool $raw_output
+ * @return string Hash string
+ */
+ static function hash($str, $raw_output = false)
+ {
+ static $hashAlgorithm = null;
+ if(is_null($hashAlgorithm))
+ {
+ if(!empty($GLOBALS['PIWIK_TRACKER_MODE']))
+ {
+ $hashAlgorithm = @Piwik_Tracker_Config::getInstance()->General['hash_algorithm'];
+ }
+ else
+ {
+ $config = Zend_Registry::get('config');
+ if($config !== false)
+ {
+ $hashAlgorithm = @$config->General->hash_algorithm;
+ }
+ }
+ }
+
+ if($hashAlgorithm)
+ {
+ $hash = @hash($hashAlgorithm, $str, $raw_output);
+ if($hash !== false)
+ return $hash;
+ }
+
+ return md5($str, $raw_output);
+ }
+
+ /**
* Returns the list of Campaign parameter names that will be read to classify
* a visit as coming from a Campaign
*
diff --git a/plugins/Login/Controller.php b/plugins/Login/Controller.php
index 5faff40844..7e4d31b188 100644
--- a/plugins/Login/Controller.php
+++ b/plugins/Login/Controller.php
@@ -18,6 +18,24 @@
class Piwik_Login_Controller extends Piwik_Controller
{
/**
+ * Generate hash on user info and password
+ *
+ * @param string $userinfo User name, email, etc
+ * @param string $password
+ * @return string
+ */
+ private function generateHash($userInfo, $password)
+ {
+ // mitigate rainbow table attack
+ $password = str_split($password, (strlen($password)/2)+1);
+ $hash = Piwik_Common::hash(
+ $userInfo . $password[0]
+ . Piwik_Common::getSalt() . $password[1]
+ );
+ return $hash;
+ }
+
+ /**
* Default action
*
* @param none
@@ -193,7 +211,7 @@ class Piwik_Login_Controller extends Piwik_Controller
*/
protected function lostPasswordFormValidated($loginMail)
{
- if( $user === 'anonymous' )
+ if( $loginMail === 'anonymous' )
{
return Piwik_Translate('Login_InvalidUsernameEmail');
}
@@ -379,7 +397,10 @@ class Piwik_Login_Controller extends Piwik_Controller
}
$expiry = strftime('%Y%m%d%H', $timestamp);
- $token = md5(Piwik_Common::getSalt() . md5($expiry . $user['login'] . $user['email'] . $user['password']));
+ $token = $this->generateHash(
+ $expiry . $user['login'] . $user['email'],
+ $user['password']
+ );
return $token;
}