<commit_before><?php

/**
 * Session handling
 * @package framework
 * @subpackage session
 */

/**
 * PHP Sessions that extend the base session class
 */
class Hm_PHP_Session extends Hm_Session {


    /* data store connection used by classes that extend this */
    public $conn;

    /**
     * Check for an existing session or a new user/pass login request
     * @param object $request request details
     * @param string $user username
     * @param string $pass password
     * @return bool
     */
    public function check($request, $user=false, $pass=false, $fingerprint=true) {
        if ($user !== false && $pass !== false) {
            if ($this->auth($user, $pass)) {
                $this->set_key($request);
                $this->loaded = true;
                $this->start($request);
                if ($fingerprint) {
                    $this->set_fingerprint($request);
                }
                else {
                    $this->set('fingerprint', false);
                }
                $this->save_auth_detail();
                $this->just_started();
            }
            else {
                Hm_Msgs::add("ERRInvalid username or password");
            }
        }
        elseif (array_key_exists($this->cname, $request->cookie)) {
            $this->get_key($request);
            $this->start($request, true);<commit_msg>refactor to simplify the php session check method<commit_after><?php

/**
 * Session handling
 * @package framework
 * @subpackage session
 */

/**
 * PHP Sessions that extend the base session class
 */
class Hm_PHP_Session extends Hm_Session {


    /* data store connection used by classes that extend this */
    public $conn;


    /**
     * Setup newly authenticated session
     * @param Hm_Request $request
     * @param boolean $fingerprint
     * @return null
     */
    private function authed($request, $fingerprint) {
        $this->set_key($request);
        $this->loaded = true;
        $this->start($request);
        if ($fingerprint) {
            $this->set_fingerprint($request);
        }
        else {
            $this->set('fingerprint', false);
        }
        $this->save_auth_detail();
        $this->just_started();
    }

    /**
     * Check for an existing session or a new user/pass login request
     * @param object $request request details
     * @param string $user username
     * @param string $pass password
     * @return bool
     */
    public function check($request, $user=false, $pass=false, $fingerprint=true) {
        if ($user !== false && $pass !== false) {
            if ($this->auth($user, $pass)) {
                $this->authed($request, $fingerprint);
            }
            else {
                Hm_Msgs::add("ERRInvalid username or password");
            }
        }
        elseif (array_key_exists($this->cname, $request->cookie)) {
            $this->get_key($request);
            $this->start($request, true);
{'fraction_non_alphanumeric': 0.12868269556383338, 'fraction_numerical': 0.0, 'mean_word_length': 1.9422310756972112, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, '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': '6095030', 'n_tokens_mistral': 818, 'n_tokens_neox': 781, 'n_words': 210}