MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //home/cafsindia/hrms_allyindian_com/application/models/Otp_model.php
<?php
class Otp_model extends CI_Model {
    private $table = 'otp_attempts';

    public function get($user_name) {
        return $this->db->get_where($this->table, ['user_name' => $user_name])->row_array();
    }

    public function increment_attempt($user_name) {
        $now = date('Y-m-d H:i:s');
        $row = $this->get($user_name);
        if ($row) {
            $data = [
                'attempts' => $row['attempts'] + 1,
                'last_attempt' => $now
            ];
            $this->db->where('user_name', $user_name)->update($this->table, $data);
        } else {
            $data = [
                'user_name' => $user_name,
                'attempts' => 1,
                'last_attempt' => $now
            ];
            $this->db->insert($this->table, $data);
        }
    }

    public function set_lock($user_name, $minutes = 15) {
        $lock_time = date('Y-m-d H:i:s', time() + $minutes * 60);
        $this->db->where('user_name', $user_name)->update($this->table, [
            'lock_time' => $lock_time
        ]);
    }

    public function reset($user_name) {
        $this->db->where('user_name', $user_name)->update($this->table, [
            'attempts' => 0, 'lock_time' => null
        ]);
    }

    public function get_status($user_name) {
        $row = $this->get($user_name);
        if (!$row) return ['attempts' => 0, 'lock_time' => null];
        return ['attempts' => $row['attempts'], 'lock_time' => $row['lock_time']];
    }
}