<commit_before><?php

class User implements IDbRecord {

    private $id = -1;
    public $username, $password, $firstName, $lastName, $passwordSalt, $createDate, $authToken;

    public function save()
    {
        if($this->id == -1)
        {
            $this->id = Database::query("INSERT INTO Users
                (username, password, first_name, last_name, password_salt, create_date, auth_token)
                VALUES (?, ?, ?, ?, ?, NOW(), ?)",
                $this->username,
                $this->password,
                $this->firstName,
                $this->lastName,
                $this->passwordSalt,
                $this->authToken
            );

            $user = User::findById($this->id);
            $this->id = $user->id;
            $this->createDate = $user->createDate;

            return $this->id;
        }
        else
        {
            return Database::query("UPDATE Users SET
                username = ?, password = ?, first_name = ?,
                last_name = ?, password_salt = ?, auth_token = ?
                WHERE id = ?",
                $this->username,
                $this->password,
                $this->firstName,
                $this->lastName,
                $this->passwordSalt,
                $this->authToken,
                $this->id
            );
        }
    }

    public function delete()
    {

    }

    public static function find($criteria = array())
    {
    }

    public static function findById($id)
    {
        $record = Database::query("SELECT * FROM Users WHERE id = ?", $id);
        if(!$record)
            return null;
        $record = $record[0];

        $user = new User;

        $user->id = $id;
        $user->username = $record["username"];
        $user->password = $record["password"];
        $user->firstName = $record["first_name"];
        $user->lastName = $record["last_name"];
        $user->passwordSalt = $record["<PASSWORD>"];
        $user->createDate = $record["create_date"];
        $user->authToken = $record["auth_token"];

        return $user;
    }

    public function getId()
    {
        return $this->id;
    }

    public static function login($username, $password)
    {

    }

    public static function register($username, $password, $firstName, $lastName)
    {
        if(Database::query("SELECT 1 FROM Users WHERE username = ?", $username))
            return false;

        $user = new User;
        $user->username = $username;
        $user->passwordSalt = Auth::generatePasswordSalt();
        $user->password = Auth::hashPassword($password, $user->passwordSalt);
        $user->firstName = $firstName;
        $user->lastName = $lastName;

        if(!$user->save())
            return false;

        return $user;
    }
} <commit_msg>added User::login method<commit_after><?php

class User implements IDbRecord {

    private $id = -1;
    public $username, $password, $firstName, $lastName, $passwordSalt, $createDate, $authToken;

    public function save()
    {
        if($this->id == -1)
        {
            $this->id = Database::query("INSERT INTO Users
                (username, password, first_name, last_name, password_salt, create_date, auth_token)
                VALUES (?, ?, ?, ?, ?, NOW(), ?)",
                $this->username,
                $this->password,
                $this->firstName,
                $this->lastName,
                $this->passwordSalt,
                $this->authToken
            );

            $user = User::findById($this->id);
            $this->id = $user->id;
            $this->createDate = $user->createDate;

            return $this->id;
        }
        else
        {
            return Database::query("UPDATE Users SET
                username = ?, password = ?, first_name = ?,
                last_name = ?, password_salt = ?, auth_token = ?
                WHERE id = ?",
                $this->username,
                $this->password,
                $this->firstName,
                $this->lastName,
                $this->passwordSalt,
                $this->authToken,
                $this->id
            );
        }
    }

    public function delete()
    {

    }

    public static function find($criteria = array())
    {
    }

    public static function findById($id)
    {
        $record = Database::query("SELECT * FROM Users WHERE id = ?", $id);
        if(!$record)
            return null;
        $record = $record[0];

        $user = new User;

        $user->id = $id;
        $user->username = $record["username"];
        $user->password = $record["password"];
        $user->firstName = $record["first_name"];
        $user->lastName = $record["last_name"];
        $user->passwordSalt = $record["password_salt"];
        $user->createDate = $record["create_date"];
        $user->authToken = $record["auth_token"];

        return $user;
    }

    public static function findByUsername($username)
    {
        $record = Database::query("SELECT * FROM Users WHERE username = ?", $username);
        if(!$record)
            return null;
        $record = $record[0];

        $user = new User;

        $user->id = $record["id"];
        $user->username = $record["username"];
        $user->password = $record["password"];
        $user->firstName = $record["first_name"];
        $user->lastName = $record["last_name"];
        $user->passwordSalt = $record["password_salt"];
        $user->createDate = $record["create_date"];
        $user->authToken = $record["auth_token"];

        return $user;
    }

    public function getId()
    {
        return $this->id;
    }

    public static function login($username, $password)
    {
        $user = User::findByUsername($username);

        if(!$user)
            return null;

        $passwordHash = $user->password;
        $passwordSalt = $user->passwordSalt;
        if(Auth::verifyPassword($password, $passwordHash, $passwordSalt))
            return $user;
        return null;
    }

    public static function register($username, $password, $firstName, $lastName)
    {
        if(Database::query("SELECT 1 FROM Users WHERE username = ?", $username))
            return null;

        $user = new User;
        $user->username = $username;
        $user->passwordSalt = Auth::generatePasswordSalt();
        $user->password = Auth::hashPassword($password, $user->passwordSalt);
        $user->firstName = $firstName;
        $user->lastName = $lastName;

        if(!$user->save())
            return null;

        return $user;
    }
} 
{'fraction_non_alphanumeric': 0.1414468837483424, 'fraction_numerical': 0.0013260645351407102, 'mean_word_length': 1.6249033255993812, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 88, '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': '7205954', 'n_tokens_mistral': 1974, 'n_tokens_neox': 1785, 'n_words': 371}