<commit_before><?php

class sfPhastUser extends sfBasicSecurityUser
{
	const USERID_NAMESPACE = 'symfony/user/sfUser/userid';
	const USERSIGNID_NAMESPACE = 'symfony/user/sfUser/signid';
	const USERSESSIONID_NAMESPACE = 'symfony/user/sfUser/sessionid';
	const AUTHTIME_NAMESPACE = 'symfony/user/sfUser/authtime';
	const CREDENTIALS_CHECK_NAMESPACE = 'symfony/user/sfUser/credentialCheck';
	protected $user;

	public function initialize(sfEventDispatcher $dispatcher, sfStorage $storage, $options = array())
	{

		parent::initialize($dispatcher, $storage, $options);

        $options = array_merge(
            [
                'check_credentials' => true
            ],
            $options
        );

 		if(!$this->isAuthenticated()){
			$cookie_id = base_convert(sfContext::getInstance()->getRequest()->getCookie('__utna'), 32, 16);
			$cookie_hash = sfContext::getInstance()->getRequest()->getCookie('__utnb');

			if($cookie_id && $cookie_hash){
                if($session = UserSessionQuery::create()->filterById($cookie_id)->filterByHash($cookie_hash)->findOne()){
                    $this->authorize($session);
                }else{
                    $this->terminate();
                }
			}
		}

        if($options['check_credentials']){
            $this->checkCredentials();
        }

    }

    protected function checkCredentials($force = false){
        if($this->isAuthenticated()){
            if($force || $this->storage->read(self::CREDENTIALS_CHECK_NAMESPACE) < time() - 60){
                $this->storage->write(self::CREDENTIALS_CHECK_NAMESPACE, time());
                $this->clearCredentials();
                $this->addCredentials($this->getObjectModel()->getCredentials());
            }
        }
    }

    /**
     * @return User
     */
	public function getObjectModel(){
		if(!$this->isAuthenticated()) return;
		$object = $this->user ? $this->user : $this->user = UserPeer::retrieveByPK($this->storage->read(self::USERID_NAMESPACE));
		if($object){
			return $object;
		}else{
			$this->terminate();
			throw new sfPhastException('Object model for user not found');
		}

	}

	public function getSession(){
		return UserSessionQuery::create()->findOneById($this->storage->read(self::USERSESSIONID_NAMESPACE));
	}

	public function getSign(){
		return UserSignQuery::create()->findOneById($this->storage->read(self::USERSIGNID_NAMESPACE));
	}

	public function generatePassword($password, $salt){
		return hash('sha256', sha1($salt.$password) . sfConfig::get('sf_user_password_salt'));
	}

	public function generateHash($md5 = false){
        return sfPhastUtils::generateHash($md5);
	}

    /**
     * @param $key
     * @param $password
     * @return bool|null|UserSign
     */
    public function verify($key, $password){
        if($sign = UserSignQuery::create()->findOneByKey($key)){
            if($sign->getPassword() == $this->generatePassword($password, $sign->getSalt())){
                return $sign;
            }<commit_msg>user -> getObject<commit_after><?php

class sfPhastUser extends sfBasicSecurityUser
{
	const USERID_NAMESPACE = 'symfony/user/sfUser/userid';
	const USERSIGNID_NAMESPACE = 'symfony/user/sfUser/signid';
	const USERSESSIONID_NAMESPACE = 'symfony/user/sfUser/sessionid';
	const AUTHTIME_NAMESPACE = 'symfony/user/sfUser/authtime';
	const CREDENTIALS_CHECK_NAMESPACE = 'symfony/user/sfUser/credentialCheck';
	protected $user;

	public function initialize(sfEventDispatcher $dispatcher, sfStorage $storage, $options = array())
	{

		parent::initialize($dispatcher, $storage, $options);

        $options = array_merge(
            [
                'check_credentials' => true
            ],
            $options
        );

 		if(!$this->isAuthenticated()){
			$cookie_id = base_convert(sfContext::getInstance()->getRequest()->getCookie('__utna'), 32, 16);
			$cookie_hash = sfContext::getInstance()->getRequest()->getCookie('__utnb');

			if($cookie_id && $cookie_hash){
                if($session = UserSessionQuery::create()->filterById($cookie_id)->filterByHash($cookie_hash)->findOne()){
                    $this->authorize($session);
                }else{
                    $this->terminate();
                }
			}
		}

        if($options['check_credentials']){
            $this->checkCredentials();
        }

    }

    protected function checkCredentials($force = false){
        if($this->isAuthenticated()){
            if($force || $this->storage->read(self::CREDENTIALS_CHECK_NAMESPACE) < time() - 60){
                $this->storage->write(self::CREDENTIALS_CHECK_NAMESPACE, time());
                $this->clearCredentials();
                $this->addCredentials($this->getObjectModel()->getCredentials());
            }
        }
    }

    /**
     * @return User
     */
	public function getObjectModel(){
		if(!$this->isAuthenticated()) return;
		$object = $this->user ? $this->user : $this->user = UserPeer::retrieveByPK($this->storage->read(self::USERID_NAMESPACE));
		if($object){
			return $object;
		}else{
			$this->terminate();
			throw new sfPhastException('Object model for user not found');
		}

	}

    public function getObject(){
        return $this->getObjectModel();
    }

	public function getSession(){
		return UserSessionQuery::create()->findOneById($this->storage->read(self::USERSESSIONID_NAMESPACE));
	}

	public function getSign(){
		return UserSignQuery::create()->findOneById($this->storage->read(self::USERSIGNID_NAMESPACE));
	}

	public function generatePassword($password, $salt){
		return hash('sha256', sha1($salt.$password) . sfConfig::get('sf_user_password_salt'));
	}

	public function generateHash($md5 = false){
        return sfPhastUtils::generateHash($md5);
	}

    /**
     * @param $key
     * @param $password
     * @return bool|null|UserSign
     */
    public function verify($key, $password){
        if($sign = UserSignQuery::create()->findOneByKey($key)){
            if($sign->getPassword() == $this->generatePassword($password, $sign->getSalt())){
                return $sign;
            }
{'fraction_non_alphanumeric': 0.15608465608465608, 'fraction_numerical': 0.003968253968253968, 'mean_word_length': 3.2182705718270572, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 81, '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': '6694354', 'n_tokens_mistral': 1881, 'n_tokens_neox': 1788, 'n_words': 272}