<commit_before><?php

/*
 * This file is part of the Galvesband TraUserBundle.
 *
 * (c) <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Galvesband\TraUserBundle\DependencyInjection;

use Doctrine\ORM\Event\PreUpdateEventArgs;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Galvesband\TraUserBundle\Entity\ResetToken;
use Galvesband\TraUserBundle\Entity\User;
use RandomLib\Factory;
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;

class UserManager
{
    protected $encoderFactory;
    /** @var  Factory */
    protected $generatorFactory;

    public function __construct(EncoderFactoryInterface $encoderFactory, Factory $generatorFactory)
    {
        $this->encoderFactory = $encoderFactory;
        $this->generatorFactory = $generatorFactory;
    }

    public function getEncoder(User $user)
    {
        return $this->encoderFactory->getEncoder($user);
    }

    /**
     * Hashes $user->getPlainPassword() and stores it with $user->setPassword().
     *
     * After this call the plain password will be empty. If
     * getPlainPassword() is empty it does nothing.
     *
     * @param User $user
     */
    public function updateUser(User $user)
    {
        $plainPassword = $user->getPlainPassword();

        $encoder = $this->getEncoder($user);
        $user->setSalt($this->generatorFactory->getMediumStrengthGenerator()->generateString(12));
        $user->setPassword($encoder->encodePassword($plainPassword, $user->getSalt()));
        $user->eraseCredentials();
    }

    public function updateResetToken(ResetToken $token)
    {
        $token->setToken($this->generatorFactory->getLowStrengthGenerator()->generateString(32));
    }

    public function preUpdate(PreUpdateEventArgs $event)
    {
        $object = $event->getEntity();

        if ($object instanceof User) {<commit_msg>FIX: Setting character set for reset tokens to 0-9 a-z A-Z.<commit_after><?php

/*
 * This file is part of the Galvesband TraUserBundle.
 *
 * (c) <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Galvesband\TraUserBundle\DependencyInjection;

use Doctrine\ORM\Event\PreUpdateEventArgs;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Galvesband\TraUserBundle\Entity\ResetToken;
use Galvesband\TraUserBundle\Entity\User;
use RandomLib\Factory;
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;

class UserManager
{
    protected $encoderFactory;
    /** @var  Factory */
    protected $generatorFactory;

    public function __construct(EncoderFactoryInterface $encoderFactory, Factory $generatorFactory)
    {
        $this->encoderFactory = $encoderFactory;
        $this->generatorFactory = $generatorFactory;
    }

    public function getEncoder(User $user)
    {
        return $this->encoderFactory->getEncoder($user);
    }

    /**
     * Hashes $user->getPlainPassword() and stores it with $user->setPassword().
     *
     * After this call the plain password will be empty. If
     * getPlainPassword() is empty it does nothing.
     *
     * @param User $user
     */
    public function updateUser(User $user)
    {
        $plainPassword = $user->getPlainPassword();

        $encoder = $this->getEncoder($user);
        $user->setSalt($this->generatorFactory->getMediumStrengthGenerator()->generateString(12));
        $user->setPassword($encoder->encodePassword($plainPassword, $user->getSalt()));
        $user->eraseCredentials();
    }

    public function updateResetToken(ResetToken $token)
    {
        $token->setToken(
            $this->generatorFactory
                ->getLowStrengthGenerator()
                ->generateString(16, '<KEY>')
        );
    }

    public function preUpdate(PreUpdateEventArgs $event)
    {
        $object = $event->getEntity();

        if ($object instanceof User) {
{'fraction_non_alphanumeric': 0.11381298571070443, 'fraction_numerical': 0.00250689395838556, 'mean_word_length': 3.375, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 48, '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': '4209746', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1074, 'n_words': 256}