<commit_before><?php

namespace App\Model;

use Doctrine\DBAL\Connection as DoctrineConnection;
use Crypt_AES;
use Crypt_RSA;

class CredentialService {

    protected $db;
    protected $table = 'credentials';
    protected $cipher;

    /**
     * Constructor
     *
     * @param DoctrineConnection $db
     */
    public function __construct(DoctrineConnection $db, $config)
    {
        // Encrypt passwords with AES if secret is set
        if (isset($config['secret']) && !empty($config['secret'])) {
            $this->cipher = new Crypt_AES(CRYPT_AES_MODE_ECB);
            $this->cipher->setKey($config['secret']);
        }

        $this->db = $db;
    }

    /**
     * Get credentials
     *
     * @param mixed $hash Hash to get credentials for
     * @return mixed Credential data
     */
    public function get($hash)
    {
        $qb = $this->db->createQueryBuilder();
        $credentials = $qb->select('userName', 'password', 'comment', 'expires')
            ->from($this->table)
            ->where($qb->expr()->andX(
                 $qb->expr()->eq('hash', '?'),
                 $qb->expr()->gt('expires', '?')
            ))
            ->setParameter(0, $hash)
            ->setParameter(1, time())
            ->execute()
            ->fetch();

        if ($this->cipher) {
            $credentials['userName'] = $this->cipher->decrypt($credentials['userName']);
            $credentials['password'] = $this->cipher->decrypt($credentials['password']);
            $credentials['comment'] = $this->cipher->decrypt($credentials['comment']);
        }

        return $credentials;
    }

    /**
     * Save credentials
     *
     * @param string $userName User name
     * @param string $password Password
     * @param string $comment Comment
     * @param int $expires Expiry period
     * @return string Hash to identify saved credentials
     */
    public function save($userName, $password, $comment, $expires)
    {
        if ($expires < 60 * 60 || $expires > 60 * 60 * 24 * 30) {
            $expires = 60 * 60;
        }<commit_msg>Fixed error when viewing deleted entry #4<commit_after><?php

namespace App\Model;

use Doctrine\DBAL\Connection as DoctrineConnection;
use Crypt_AES;
use Crypt_RSA;

class CredentialService {

    protected $db;
    protected $table = 'credentials';
    protected $cipher;

    /**
     * Constructor
     *
     * @param DoctrineConnection $db
     */
    public function __construct(DoctrineConnection $db, $config)
    {
        // Encrypt passwords with AES if secret is set
        if (isset($config['secret']) && !empty($config['secret'])) {
            $this->cipher = new Crypt_AES(CRYPT_AES_MODE_ECB);
            $this->cipher->setKey($config['secret']);
        }

        $this->db = $db;
    }

    /**
     * Get credentials
     *
     * @param mixed $hash Hash to get credentials for
     * @return mixed Credential data
     */
    public function get($hash)
    {
        $qb = $this->db->createQueryBuilder();
        $credentials = $qb->select('userName', 'password', 'comment', 'expires')
            ->from($this->table)
            ->where($qb->expr()->andX(
                 $qb->expr()->eq('hash', '?'),
                 $qb->expr()->gt('expires', '?')
            ))
            ->setParameter(0, $hash)
            ->setParameter(1, time())
            ->execute()
            ->fetch();

        if ($this->cipher && $credentials) {
            $credentials['userName'] = $this->cipher->decrypt($credentials['userName']);
            $credentials['password'] = $this->cipher->decrypt($credentials['password']);
            $credentials['comment'] = $this->cipher->decrypt($credentials['comment']);
        }

        return $credentials;
    }

    /**
     * Save credentials
     *
     * @param string $userName User name
     * @param string $password Password
     * @param string $comment Comment
     * @param int $expires Expiry period
     * @return string Hash to identify saved credentials
     */
    public function save($userName, $password, $comment, $expires)
    {
        if ($expires < 60 * 60 || $expires > 60 * 60 * 24 * 30) {
            $expires = 60 * 60;
        }
{'fraction_non_alphanumeric': 0.15410305343511452, 'fraction_numerical': 0.008826335877862596, 'mean_word_length': 2.178923426838514, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 59, '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': '6628274', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1186, 'n_words': 277}