use of password_hash() rather than crypt() - refs BT#16297

And better documentation.
pull/3353/head
Sébastien Ducoulombier 6 years ago
parent 4119841b9c
commit 7f35e5da57
  1. 14
      plugin/userremoteservice/Entity/UserRemoteService.php
  2. 10
      plugin/userremoteservice/lang/english.php
  3. 11
      plugin/userremoteservice/lang/french.php
  4. 4
      plugin/userremoteservice/src/user_remote_service_plugin.class.php

@ -99,21 +99,21 @@ class UserRemoteService
/**
* Returns a user-specific URL, with two extra query string parameters : 'username' and 'hash'.
* 'hash' is the return value of function call crypt($userId, $salt).
* 'hash' is generated using $salt and $userId.
*
* @param string $username the URL query parameter 'username'
* @param string $userId the user identifier, to be passed to crypt() to generate the 'hash' query parameter
* @param string $salt the salt to be passed to crypt() in order to generate the 'hash' query parameter
* @param string $userId the user identifier, to build the hash
* @param string $salt the salt, to build the hash
*
* @throws Exception on crypt() failure
* @throws Exception on hash generation failure
*
* @return string the custom user URL
*/
public function getCustomUserURL($username, $userId, $salt)
{
$hash = crypt($userId, $salt);
if (is_null($hash)) {
throw new Exception('crypt() failed');
$hash = password_hash($salt.$userId, PASSWORD_BCRYPT);
if (false === $hash) {
throw new Exception('hash generation failed');
}
return sprintf(
'%s%s%s',

@ -5,7 +5,15 @@ $strings['plugin_title'] = 'User Remote Services';
$strings['plugin_comment'] = 'Appends site-specific iframe-targetted user-identifying links to the menu bar.';
$strings['salt'] = 'Salt';
$strings['salt_help'] = '"hash" URL query string parameter crypt() salt';
$strings['salt_help'] = <<<'EOT'
Secret character string, used to generate the <em>hash</em> URL parameter. The longest, the best.
<br/>Remote user services can check the generated URL authenticity with the following PHP expression :
<br/><code class="php">password_verify($salt.$userId, $hash)</code>
<br/>Where
<br/><code>$salt</code> is this input value,
<br/><code>$userId</code> is the number of the user referenced by the <em>username</em> URL parameter value and
<br/><code>$hash</code> contains the <em>hash</em> URL parameter value.
EOT;
// Please keep alphabetically sorted
$strings['CreateService'] = 'Add service to menu bar';

@ -7,8 +7,15 @@ $strings['plugin_comment'] =
/* Strings for settings */
$strings['salt'] = "Sel";
$strings['salt_help'] =
"Sel ('salt') à passer à la fonction crypt() pour générer le paramètre d'URL 'hash' des liens générés.";
$strings['salt_help'] = <<<'EOT'
Chaine de caractère secrète, utilisée pour générer le paramètre d'URL <em>hash</em>. Plus il est long et mieux c'est.
<br/>Les services distants peuvent vérifier la validité de l'URL générée avec l'expression PHP suivante :
<br/><code class="php">password_verify($salt.$userId, $hash)</code>
<br/>
<br/><code>$salt</code> est la valeur saisie ici,
<br/><code>$userId</code> est le numéro de l'utilisateur auquel fait référence le paramètre d'URL <em>username</em> et
<br/><code>$hash</code> représente la valeur du paramètre d'URL <em>hash</em>.
EOT;
// Please keep alphabetically sorted
$strings['CreateService'] = "Ajouter le service au menu";

@ -140,8 +140,6 @@ OEQ,
*
* @see \return_navigation_array
*
* @throws Exception on crypt() failure
*
* @return array menu items
*/
public function getNavigationMenu()
@ -262,7 +260,7 @@ OEQ,
/**
* Generates the iframe HTML element to load a service URL
*
* @throws Exception on crypt() failure
* @throws Exception on hash generation failure
*
* @return string the iframe HTML element
*/

Loading…
Cancel
Save