<commit_before><?php
namespace Neos\Flow\Security\Authentication\Token;

/*
 * This file is part of the Neos.Flow package.
 *
 * (c) Contributors of the Neos Project - www.neos.io
 *
 * This package is Open Source Software. For the full copyright and license
 * information, please view the LICENSE file which was distributed with this
 * source code.
 */

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Utility\ObjectAccess;

/**
 * An authentication token used for simple password authentication.
 */
class PasswordToken extends AbstractToken implements PasswordTokenInterface
{
    /**
     * The password credentials
     * @var array
     * @Flow\Transient
     */
    protected $credentials = ['password' => ''];

    /**
     * @var \Neos\Flow\Utility\Environment
     * @Flow\Inject
     */
    protected $environment;

    /**
     * Updates the password credential from the POST vars, if the POST parameters
     * are available. Sets the authentication status to AUTHENTICATION_NEEDED, if credentials have been sent.
     *
     * Note: You need to send the password in this POST parameter:
     *       __authentication[Neos][Flow][Security][Authentication][Token][PasswordToken][password]
     *
     * @param ActionRequest $actionRequest The current action request
     * @return void
     */
    public function updateCredentials(ActionRequest $actionRequest)
    {
        if ($actionRequest->getHttpRequest()->getMethod() !== 'POST') {
            return;
        }

        $postArguments = $actionRequest->getInternalArguments();
        $password = ObjectAccess::getPropertyPath($postArguments, '__authentication.Neos.Flow.Security.Authentication.Token.PasswordToken.password');

        if (!empty($password)) {
            $this->credentials['password'] = $password;
            $this->setAuthenticationStatus(self::AUTHENTICATION_NEEDED);
        }
    }

    /**
     * @return string the password this token represents, or an empty string
     */
    public function getPassword(): string
    {
        return $this->credentials['password'] ?? '';
    }

    /**
     * Returns a string representation of the token for logging purposes.
     *
     * @return string
     */
    public function __toString()<commit_msg>Make PasswordToken post field names configurable, too<commit_after><?php
namespace Neos\Flow\Security\Authentication\Token;

/*
 * This file is part of the Neos.Flow package.
 *
 * (c) Contributors of the Neos Project - www.neos.io
 *
 * This package is Open Source Software. For the full copyright and license
 * information, please view the LICENSE file which was distributed with this
 * source code.
 */

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Security\Exception\InvalidAuthenticationStatusException;
use Neos\Utility\ObjectAccess;

/**
 * An authentication token used for simple password authentication.
 */
class PasswordToken extends AbstractToken implements PasswordTokenInterface
{

    private const DEFAULT_PASSWORD_POST_FIELD = '__authentication.Neos.Flow.Security.Authentication.Token.PasswordToken.password';

    /**
     * The password credentials
     * @var array
     * @Flow\Transient
     */
    protected $credentials = ['password' => ''];

    /**
     * Updates the password credential from the POST vars, if the POST parameters
     * are available. Sets the authentication status to AUTHENTICATION_NEEDED, if credentials have been sent.
     *
     * Note: You need to send the password in this POST parameter:
     *       __authentication[Neos][Flow][Security][Authentication][Token][PasswordToken][password]
     *
     * @param ActionRequest $actionRequest The current action request
     * @return void
     * @throws InvalidAuthenticationStatusException
     */
    public function updateCredentials(ActionRequest $actionRequest)
    {
        if ($actionRequest->getHttpRequest()->getMethod() !== 'POST') {
            return;
        }
        $allArguments = array_merge($actionRequest->getArguments(), $actionRequest->getInternalArguments());
        $passwordFieldName = $this->options['passwordPostField'] ?? self::DEFAULT_PASSWORD_POST_FIELD;
        $password = ObjectAccess::getPropertyPath($allArguments, $passwordFieldName);
        if (!empty($password)) {
            $this->credentials['password'] = $password;
            $this->setAuthenticationStatus(self::AUTHENTICATION_NEEDED);
        }
    }

    /**
     * @return string the password this token represents, or an empty string
     */
    public function getPassword(): string
    {
        return $this->credentials['password'] ?? '';
    }

    /**
     * Returns a string representation of the token for logging purposes.
     *
     * @return string
     */
    public function __toString()
{'fraction_non_alphanumeric': 0.1015576323987539, 'fraction_numerical': 0.0, 'mean_word_length': 3.2024432809773122, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4551314', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1215, 'n_words': 362}