<commit_before><?php
/**
 * @license See the LICENSE file that was distributed with this source code.
 */

namespace Guzzle\Openstack\Identity\Command;

use Guzzle\Openstack\Common\Command\AbstractJsonCommand;

/**
 * Requests a new token for username
 *
 * @guzzle username doc="Username" required="true"
 * @guzzle password doc="Password" required="true"
 * @guzzle tenantid doc="Tenant Id"
 */
class Authenticate extends AbstractJsonCommand
{
    /**
     * Set the username
     *
     * @param string $username
     *
     * @return Authenticate
     */
    public function setUsername($username)
    {
        return $this->set('username', $username);
    }

    /**
     * Set the password
     *
     * @param string $password
     *
     * @return Authenticate
     */
    public function setPassword($password)
    {
        return $this->set('password', $password);
    }

    /**
     * Set the tenant_id
     *
     * @param string $tenantId
     *
     * @return Authenticate
     */
    public function setTenantid($tenantId)
    {
        return $this->set('tenantid', $tenantId);
    }

    /**
     * Set the tenant name
     *
     * @param string $tenantName
     *
     * @return Authenticate
     */
    public function setTenantname($tenantName)
    {
        return $this->set('tenantname', $tenantName);
    }    
    
    protected function build()
    {
        $data = array(
            'auth' => array(
                'passwordCredentials' => array(
                    'username' => $this->get('username'),
                    'password' => $this->get('password')
                )
            )
        );
        if($this->hasKey('tenantid')){
            $data['auth']['tenantId'] = $this->get('tenantid');
        }
        if($this->hasKey('tenantname')){
            $data['auth']['tenantName'] = $this->get('tenantname');
        }
        $body = json_encode($data);
        $this->request = $this->client->post('tokens', null, $body);        
    }
}<commit_msg>Added null check to prevent injection of 'null' values in the JSON message.<commit_after><?php
/**
 * @license See the LICENSE file that was distributed with this source code.
 */

namespace Guzzle\Openstack\Identity\Command;

use Guzzle\Openstack\Common\Command\AbstractJsonCommand;

/**
 * Requests a new token for username
 *
 * @guzzle username doc="Username" required="true"
 * @guzzle password doc="Password" required="true"
 * @guzzle tenantid doc="Tenant Id"
 */
class Authenticate extends AbstractJsonCommand
{
    /**
     * Set the username
     *
     * @param string $username
     *
     * @return Authenticate
     */
    public function setUsername($username)
    {
        return $this->set('username', $username);
    }

    /**
     * Set the password
     *
     * @param string $password
     *
     * @return Authenticate
     */
    public function setPassword($password)
    {
        return $this->set('password', $password);
    }

    /**
     * Set the tenant_id
     *
     * @param string $tenantId
     *
     * @return Authenticate
     */
    public function setTenantid($tenantId)
    {
        return $this->set('tenantid', $tenantId);
    }

    /**
     * Set the tenant name
     *
     * @param string $tenantName
     *
     * @return Authenticate
     */
    public function setTenantname($tenantName)
    {
        return $this->set('tenantname', $tenantName);
    }    
    
    protected function build()
    {
        $data = array(
            'auth' => array(
                'passwordCredentials' => array(
                    'username' => $this->get('username'),
                    'password' => $this->get('password')
                )
            )
        );
        if($this->hasKey('tenantid') && !is_null($this->get('tenantid'))){
            $data['auth']['tenantId'] = $this->get('tenantid');
        }
        if($this->hasKey('tenantname') && !is_null($this->get('tenantname'))){
            $data['auth']['tenantName'] = $this->get('tenantname');
        }
        $body = json_encode($data);
        $this->request = $this->client->post('tokens', null, $body);        
    }
}
{'fraction_non_alphanumeric': 0.1460647030420087, 'fraction_numerical': 0.0, 'mean_word_length': 2.0917910447761194, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7387621', 'n_tokens_mistral': 1203, 'n_tokens_neox': 1211, 'n_words': 256}