/**
  * Checks if the provided CURRENT password is correct and calls the parent
  * class function if so. Otherwise provides error message.
  *
  * @see the parent class function for parameters and return value
  */
 public function recordUserSettings()
 {
     try {
         $passwordCurrent = Common::getRequestvar('passwordCurrent', false);
         $passwordCurrent = Crypto::decrypt($passwordCurrent);
         // Note: Compare loosely, so both, "" (password input empty; forms send strings)
         //       and "password input not sent" are covered - see
         //       https://secure.php.net/manual/en/types.comparisons.php
         if ($passwordCurrent != "") {
             $userName = Piwik::getCurrentUserLogin();
             // gets username as string or "anonymous"
             // see Piwik\Plugins\Login\Auth for used password hash function
             // (in setPassword()) and access to hashed password (in getTokenAuthSecret())
             if ($userName != 'anonymous') {
                 $model = new Model();
                 $user = $model->getUser($userName);
                 if (UsersManagerEncrypted::getPasswordHash($passwordCurrent) === $user['password']) {
                     $toReturn = parent::recordUserSettings();
                 } else {
                     throw new Exception(Piwik::translate('UsersManagerEncrypted_CurrentPasswordIncorrect'));
                 }
             } else {
                 throw new Exception(Piwik::translate('UsersManagerEncrypted_UserNotAuthenticated'));
             }
         } else {
             throw new Exception(Piwik::translate('UsersManagerEncrypted_CurrentPasswordNotProvided'));
         }
     } catch (Exception $e) {
         $response = new ResponseBuilder(Common::getRequestVar('format'));
         $toReturn = $response->getResponseException($e);
     }
     return $toReturn;
 }
Ejemplo n.º 2
0
 /**
  * Decrypts the password (if encrypted) and calls the original function on
  * the decrypted value.
  *
  * @see the parent class function for parameters and return value
  */
 public function updateUser($userLogin, $password = false, $email = false, $alias = false, $_isPasswordHashed = false, $directCall = false)
 {
     // check if this function is called directly
     // Reason: updateUser() is called in following situations:
     //         1. With an already decrypted password by:
     //            * Piwik\Plugins\Login\PasswordResetter::confirmNewPassword()
     //              on password change via the form before login
     //            * Controller::processPasswordChange() when any user changes
     //              their own password in their account settings
     //         2. With an encrypted password when called directly by (so,
     //            decryption is needed in this case):
     //            * /plugins/UsersManagerEncrypted/javascripts/usersManager.js::sendUpdateUserAJAX()
     //              when a super user changes someone's password in Piwik user administration.
     if ($directCall == 'true') {
         $password = Crypto::decrypt($password);
     }
     return parent::updateUser($userLogin, $password, $email, $alias, $_isPasswordHashed);
 }
Ejemplo n.º 3
0
 private function createGenerateKeysSetting()
 {
     $this->generateKeys = new SystemSetting('generateKeys', Piwik::translate('LoginEncrypted_SettingsGenerateKeysTitle'));
     $this->generateKeys->readableByCurrentUser = true;
     $this->generateKeys->type = static::TYPE_BOOL;
     $this->generateKeys->uiControlType = static::CONTROL_CHECKBOX;
     $this->generateKeys->description = Piwik::translate('LoginEncrypted_SettingsGenerateKeysDescription');
     $this->generateKeys->defaultValue = false;
     $this->generateKeys->transform = function ($value, $setting) {
         // check if check box got activated, and generate keys if so
         if ($value != $setting->defaultValue) {
             $publickey = Crypto::generateKeys($this->keyLength->getValue());
             $this->publicKey->setValue($publickey['e'] . ', ' . $publickey['n']);
         }
         return $setting->defaultValue;
         // reset checkbox
     };
     $this->addSetting($this->generateKeys);
 }
 /**
  * Generates new keys and stores them in all the places necessary. Existing keys will be overwritten.
  */
 protected function generateKeysAndStoreAll()
 {
     $settings = new Settings();
     // generate keys and store the private key in DB, and the public key in the JS file
     // Notes: - Key length with be the one configured in the plugin settings, or the default
     //          from there if none has been configured yet.
     $publickey = Crypto::generateKeys($settings->keyLength->getValue());
     // store the public key in plugin settings as well, for viewing purposes
     $settings->publicKey->setValue($publickey['e'] . ', ' . $publickey['n']);
     $settings->save();
 }
Ejemplo n.º 5
0
 /**
  * Gets the password from the HTML form, decrypts it and writes the decrypted
  * value back into the _POST request.
  * Note: Writing to _POST directly, as there doesn't seem to be another way. E.g., if
  *       value is replaced as in https://pear.php.net/manual/en/package.html.html-quickform2.qf-migration.php
  *       (using array_unshift()), it would not persist, as a "new" object instance
  *       will re-read its sources (i.e. _POST).
  *
  * @param QuickForm2 $form The HTML form which the password is part of
  * @param string $passwordInputId The input ID of the password field on the HTML form
  * @throws Exception if decryption fails
  */
 protected function decryptPassword($form, $passwordInputId)
 {
     $password = $form->getSubmitValue($passwordInputId);
     // check if a password was submitted
     // Note: Compare loosely, so both, "" (password input empty; forms send strings)
     //       and NULL (password input not sent - see QuickForm2->getSubmitValue())
     //       are covered - see https://secure.php.net/manual/en/types.comparisons.php
     if ($password != "") {
         // decrypt and replace password
         $password = Crypto::decrypt($password);
         if ($password === Crypto::DECRYPTION_FAILED) {
             throw new Exception(Piwik::translate('LoginEncrypted_DecryptionError'));
         }
         $_POST[$passwordInputId] = $password;
     }
 }