Skip to content

Commit

Permalink
Abandoned MD5 password encoding, defined BCRYPT as default password e…
Browse files Browse the repository at this point in the history
…ncoder
  • Loading branch information
mjansenDatabay committed Jul 7, 2016
1 parent 8a379b1 commit 37f8cfc
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 173 deletions.
108 changes: 1 addition & 107 deletions Services/Password/classes/encoders/class.ilBcryptPasswordEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
/* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */

require_once 'Services/Password/classes/class.ilBasePasswordEncoder.php';
require_once 'Services/Password/interfaces/interface.ilPasswordEncoderConfigurationFormAware.php';

/**
* Class ilBcryptPasswordEncoder
* @author Michael Jansen <mjansen@databay.de>
* @package ServicesPassword
*/
class ilBcryptPasswordEncoder extends ilBasePasswordEncoder implements ilPasswordEncoderConfigurationFormAware
class ilBcryptPasswordEncoder extends ilBasePasswordEncoder
{
/**
* @var int
Expand Down Expand Up @@ -274,17 +273,6 @@ public function getClientSaltLocation()
return ilUtil::getDataDir() . '/' . self::SALT_STORAGE_FILENAME;
}

/**
*
*/
private function generateClientSalt()
{
require_once 'Services/Password/classes/class.ilPasswordUtils.php';
$this->setClientSalt(
substr(str_replace('+', '.', base64_encode(ilPasswordUtils::getBytes(self::MIN_SALT_SIZE))), 0, 22)
);
}

/**
*
*/
Expand All @@ -299,98 +287,4 @@ private function readClientSalt()
}
}
}

/**
* @throws ilPasswordException
*/
private function storeClientSalt()
{
$result = @file_put_contents($this->getClientSaltLocation(), $this->getClientSalt());
if(!$result)
{
throw new ilPasswordException("Could not store the client salt. Please contact an administrator.");
}
}

/**
* {@inheritdoc}
* @throws ilPasswordException
*/
public function onSelection()
{
if(!$this->getClientSalt())
{
try
{
$this->generateClientSalt();
$this->storeClientSalt();
}
catch(ilPasswordException $e)
{
$this->setClientSalt(null);
throw $e;
}
}
}

/**
* {@inheritdoc}
*/
public function validateForm(ilPropertyFormGUI $form)
{
/**
* @var $lng ilLanguage
*/
global $lng;

if(!strlen(trim($this->getClientSalt())) || !preg_match('/^.{' . self::MIN_SALT_SIZE . ',}$/', $this->getClientSalt()))
{
$form->getItemByPostVar('bcrypt_salt')->setAlert($lng->txt('passwd_encoder_bcrypt_client_salt_invalid'));
return false;
}

return true;
}

/**
* {@inheritdoc}
*/
public function saveForm(ilPropertyFormGUI $form)
{
}

/**
* {@inheritdoc}
*/
public function buildForm(ilPropertyFormGUI $form)
{
/**
* @var $lng ilLanguage
*/
global $lng;

$header = new ilFormSectionHeaderGUI();
$header->setTitle($lng->txt('passwd_encoder_' . $this->getName()));
$form->addItem($header);

$salt = new ilCustomInputGUI($lng->txt('passwd_encoder_bcrypt_client_salt'), 'bcrypt_salt');

$info = array($lng->txt('passwd_encoder_client_bcrypt_salt_info'));
if(!$this->isBcryptSupported())
{
$info[] = sprintf($lng->txt('passwd_encoder_client_bcrypt_salt_info_php537'), PHP_VERSION);
}
if(1 == count($info))
{
$salt->setInfo(current($info));
}
else
{
$salt->setInfo('<ul><li>' . implode('</li><li>', $info) . '</li></ul>');
}

$salt->setHtml($this->getClientSaltLocation());

$form->addItem($salt);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */

require_once 'Services/Password/classes/class.ilBasePasswordEncoder.php';
require_once 'Services/Password/interfaces/interface.ilPasswordEncoderConfigurationFormAware.php';

/**
* Class ilMd5PasswordEncoder
Expand All @@ -12,7 +11,7 @@
* @author Michael Jansen <mjansen@databay.de>
* @package ServicesPassword
*/
class ilMd5PasswordEncoder extends ilBasePasswordEncoder implements ilPasswordEncoderConfigurationFormAware
class ilMd5PasswordEncoder extends ilBasePasswordEncoder
{
/**
* @param array $config
Expand Down Expand Up @@ -59,33 +58,4 @@ public function requiresSalt()
{
return false;
}

/**
* {@inheritdoc}
*/
public function buildForm(ilPropertyFormGUI $form)
{
}

/**
* {@inheritdoc}
*/
public function validateForm(ilPropertyFormGUI $form)
{
return true;
}

/**
* {@inheritdoc}
*/
public function saveForm(ilPropertyFormGUI $form)
{
}

/**
* {@inheritdoc}
*/
public function onSelection()
{
}
}

This file was deleted.

0 comments on commit 37f8cfc

Please sign in to comment.