<commit_before><?php 

class Database extends PDO {

	function __construct() {
    	try {
    		parent::__construct('mysql:dbname=match;host=localhost', getenv("MYSQL_USER"), getenv("MYSQL_PASSWORD"));
    		$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('DBStatement', array($this)));
		} catch (PDOException $e) {
			throw $e;
		}
	}
	
	function authenticationCredentials($user, $password) {
		$statement = $this->prepare("SELECT * FROM users WHERE username = :username AND password = :password LIMIT 1");
		$statement->bindValue(':username',$user);
		$hashedPassword = hash("sha256","^<PASSWORD>".$password);
		$statement->bindValue(':password', $hashedPassword);
		$statement->execute();
		if($statement->rowCount() == 0){
			return false;
		}else{
			return $statement->fetch(PDO::FETCH_ASSOC);
		}
	}
}

class DBStatement extends PDOStatement{
    public $dbh;

    protected function __construct($dbh){
        $this->dbh = $dbh;
        $this->setFetchMode(PDO::FETCH_OBJ);
    }
    
    public function foundRows(){
        $rows = $this->dbh->prepare('SELECT found_rows() AS rows', array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => TRUE));
        $rows->execute();
        $rowsCount = $rows->fetch(PDO::FETCH_OBJ)->rows;
        $rows->closeCursor();
        return $rowsCount;
    }
}
?><commit_msg>Updated database class with user actions<commit_after><?php 

class Database extends PDO {

	function __construct() {
    	try {
    		parent::__construct('mysql:dbname=match;host=localhost', getenv("MYSQL_USER"), getenv("MYSQL_PASSWORD"));
    		$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('DBStatement', array($this)));
		} catch (PDOException $e) {
			throw $e;
		}
	}
	
	function authenticationCredentials($username, $password) {
		$statement = $this->prepare("SELECT * FROM users WHERE username = :username AND password = :password LIMIT 1");
		$statement->bindValue(':username',$username);
		$password = $this->encryptPassword($password);
		$statement->bindValue(':password', $password);
		$statement->execute();
		if($statement->rowCount() == 0){
			return false;
		}else{
				return $statement->fetch(PDO::FETCH_ASSOC);
		}
	}
	
	function addUserToDatabase($username, $password, $type, $active=true) {
	
		$statement = $this->prepare("INSERT INTO `users` (`id`, `username`, `password`, `type`, `active`) VALUES (NULL,:username,:password,:type,:active)");
		$statement->bindParam(':username',$username);
		$password = $this-><PASSWORD>($password);
		$statement->bindParam(':password',$password);
		$statement->bindParam(':type',$type);
		$statement->bindParam(':active',$active);
		
		return $statement->execute();
	}
	
	function changeUserPassword($username, $password, $newPassword){
		$statement = $this->prepare("UPDATE `users` SET password = :newPassword WHERE username = :username AND password = :password");
		
		$newPassword = $this-><PASSWORD>($newPassword);
		$password = $this-><PASSWORD>($password);
		
		$statement->bindParam(':newPassword', $newPassword);
		$statement->bindParam(':username', $username);
		$statement->bindParam(':password', $password);
		
		return $statement->execute();
	}
	
	private function encryptPassword($password){
		return hash("sha256","^<PASSWORD>".$password);
	}
}

class DBStatement extends PDOStatement {

    public $dbh;

    protected function __construct($dbh) {
        $this->dbh = $dbh;
        $this->setFetchMode(PDO::FETCH_OBJ);
    }
    
    public function foundRows() {
        $rows = $this->dbh->prepare('SELECT found_rows() AS rows', array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => TRUE));
        $rows->execute();
        $rowsCount = $rows->fetch(PDO::FETCH_OBJ)->rows;
        $rows->closeCursor();
        return $rowsCount;
    }
}
?>
{'fraction_non_alphanumeric': 0.17520794204453985, 'fraction_numerical': 0.002683123155352831, 'mean_word_length': 4.67427701674277, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 57, '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': '2165801', 'n_tokens_mistral': 1253, 'n_tokens_neox': 1169, 'n_words': 212}