<commit_before><?php
/**
 * Nooku Framework - http://www.nooku.org
 *
 * @copyright	Copyright (C) 2011 - 2013 <NAME> and Timble CVBA. (http://www.timble.net)
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link		git://git.assembla.com/nooku-framework.git for the canonical source repository
 */

namespace Nooku\Component\Users;

use Nooku\Library;

/**
 * Password Database Row
 *
 * @author  <NAME> <http://nooku.assembla.com/profile/arunasmazeika>
 * @package Nooku\Component\Users
 */
class DatabaseRowPassword extends Library\DatabaseRowTable
{
    /**
     * Minimum password length
     *
     * @var integer
     */
    protected $_length;

    public function __construct(Library\ObjectConfig $config)
    {
        parent::__construct($config);

        //Set the minimum passowrd length
        $this->_length = $config->length;

        // TODO Remove when PHP 5.5 becomes a requirement.
        require_once JPATH_ROOT.'/component/users/legacy/password.php';
    }

    /**
     * Initializes the default configuration for the object
     *
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param  Library\ObjectConfig $config  An optional ObjectConfig object with configuration options.
     * @return void
     */
    protected function _initialize(Library\ObjectConfig $config)
    {
        $config->append(array(
            'length' => 5
        ));

        parent::_initialize($config);
    }

    public function save()
    {
        $user = $this->getObject('com:users.model.users')
            ->email($this->id)
            ->getRow();

        // Check if referenced user actually exists.
        if ($user->isNew())
        {
            $this->setStatus(Library\Database::STATUS_FAILED);
            $this->setStatusMessage(\JText::sprintf('USER NOT FOUND', $this->id));
            return false;
        }

        if ($password = $this->password)
        {
            // Check the password length.
            if (strlen($password) < $this->_length)
            {
                $this->setStatus(Library\Database::STATUS_FAILED);
                $this->setStatusMessage(\JText::sprintf('PASSWORD TOO SHORT', $this->_length));
                return false;
            }

            if (!$this->isNew())
            {
                // Check if new and current hashes are the same.
                if ($this->verify($password))
                {
                    $this->setStatus(Library\Database::STATUS_FAILED);
                    $this->setStatusMessage(\JText::_('New and old passwords are the same'));
                    return false;
                }
            }

            // Reset expiration date.
            $this->resetExpiration(false);

            // Create hash.
            $this->hash = $this->getHash($password);

            // Clear reset.
            $this->reset = '';<commit_msg>re #352 Make behavior check before calling mixed methods.<commit_after><?php
/**
 * Nooku Framework - http://www.nooku.org
 *
 * @copyright	Copyright (C) 2011 - 2013 <NAME> and Timble CVBA. (http://www.timble.net)
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link		git://git.assembla.com/nooku-framework.git for the canonical source repository
 */

namespace Nooku\Component\Users;

use Nooku\Library;

/**
 * Password Database Row
 *
 * @author  <NAME> <http://nooku.assembla.com/profile/arunasmazeika>
 * @package Nooku\Component\Users
 */
class DatabaseRowPassword extends Library\DatabaseRowTable
{
    /**
     * Minimum password length
     *
     * @var integer
     */
    protected $_length;

    public function __construct(Library\ObjectConfig $config)
    {
        parent::__construct($config);

        //Set the minimum passowrd length
        $this->_length = $config->length;

        // TODO Remove when PHP 5.5 becomes a requirement.
        require_once JPATH_ROOT.'/component/users/legacy/password.php';
    }

    /**
     * Initializes the default configuration for the object
     *
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param  Library\ObjectConfig $config  An optional ObjectConfig object with configuration options.
     * @return void
     */
    protected function _initialize(Library\ObjectConfig $config)
    {
        $config->append(array(
            'length' => 5
        ));

        parent::_initialize($config);
    }

    public function save()
    {
        $user = $this->getObject('com:users.model.users')
            ->email($this->id)
            ->getRow();

        // Check if referenced user actually exists.
        if ($user->isNew())
        {
            $this->setStatus(Library\Database::STATUS_FAILED);
            $this->setStatusMessage(\JText::sprintf('USER NOT FOUND', $this->id));
            return false;
        }

        if ($password = $this->password)
        {
            // Check the password length.
            if (strlen($password) < $this->_length)
            {
                $this->setStatus(Library\Database::STATUS_FAILED);
                $this->setStatusMessage(\JText::sprintf('PASSWORD TOO SHORT', $this->_length));
                return false;
            }

            if (!$this->isNew())
            {
                // Check if new and current hashes are the same.
                if ($this->verify($password))
                {
                    $this->setStatus(Library\Database::STATUS_FAILED);
                    $this->setStatusMessage(\JText::_('New and old passwords are the same'));
                    return false;
                }
            }

            // Reset expiration date.
            if ($this->isExpirable())
            {
                $this->resetExpiration(false);
            }

            // Create hash.
            $this->hash = $this->getHash($password);

            // Clear reset.
            $this->reset = '';
{'fraction_non_alphanumeric': 0.12723289518031683, 'fraction_numerical': 0.00455005055611729, 'mean_word_length': 1.8852698104035002, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 62, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4879793', 'n_tokens_mistral': 1659, 'n_tokens_neox': 1596, 'n_words': 372}