<commit_before><?php

/*
 * This file is part of Slim HTTP Basic Authentication middleware
 *
 * Copyright (c) 2013-2014 <NAME>
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Project home:
 *   https://github.com/tuupola/slim-basic-auth
 *
 */

namespace Slim\Middleware\HttpBasicAuthentication;

class PdoAuthenticator implements AuthenticatorInterface
{
    private $options;

    public function __construct(array $options = array())
    {

        /* Default options. */
        $this->options = array(
            "table" => "users",
            "user" => "user",
            "hash" => "hash"
        );

        if ($options) {
            $this->options = array_merge($this->options, $options);
        }
    }

    public function authenticate($user, $pass)
    {
        $statement = $this->options["pdo"]->prepare(
            "SELECT *
             FROM {$this->options['table']}
             WHERE {$this->options['user']} = ?
             LIMIT 1"
        );

        $statement->execute(array($user));

        if ($user = $statement->fetch(\PDO::FETCH_ASSOC)) {
            return password_verify($pass, $user[$this->options["hash"]]);
        }

        return false;
    }
}<commit_msg>Add conditional PDO statement for sqlsrv <commit_after><?php

/*
 * This file is part of Slim HTTP Basic Authentication middleware
 *
 * Copyright (c) 2013-2014 <NAME>
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Project home:
 *   https://github.com/tuupola/slim-basic-auth
 *
 */

namespace Slim\Middleware\HttpBasicAuthentication;

class PdoAuthenticator implements AuthenticatorInterface
{
    private $options;

    public function __construct(array $options = array())
    {

        /* Default options. */
        $this->options = array(
            "table" => "users",
            "user" => "user",
            "hash" => "hash"
        );

        if ($options) {
            $this->options = array_merge($this->options, $options);
        }
    }

    public function authenticate($user, $pass)
    {
         if($this->options["pdo"]->getAttribute(\PDO::ATTR_DRIVER_NAME) === "sqlsrv"){
    
         $statement = $this->options["pdo"]->prepare(
                "SELECT top 1 *
                 FROM {$this->options['table']}
                 WHERE {$this->options['user']} = ?"
             );
    
        }else{
            $statement = $this->options["pdo"]->prepare(
                 "SELECT *
                  FROM {$this->options['table']}
                  WHERE {$this->options['user']} = ?
                  LIMIT 1"
        );
        	
    }  


        $statement->execute(array($user));

        if ($user = $statement->fetch(\PDO::FETCH_ASSOC)) {
            return password_verify($pass, $user[$this->options["hash"]]);
        }

        return false;
    }
}
{'fraction_non_alphanumeric': 0.15251897860593513, 'fraction_numerical': 0.006556245686680469, 'mean_word_length': 2.0041450777202074, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 37, 'https://': 2, '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': '5526970', 'n_tokens_mistral': 864, 'n_tokens_neox': 826, 'n_words': 166}