<?php
namespace App\Models;

use CodeIgniter\Model;

class AuthModel extends Model
{
    protected $table = 'users';
    protected $primaryKey = 'id'; // Ganti "id" dengan nama kolom kunci utama
    protected $allowedFields = ['username', 'email', 'phone', 'firstname', 'lastname', 'password', 'salt'];



    public function authenticate($username, $password)
    {
        $user = $this->where('username', $username)->first();

        if ($user) {
            // Verifikasi kata sandi dengan salt
            if (password_verify($password . $user['salt'], $user['password'])) {
                return $user;
            }
        }

        return null;
    }

    public function getUserByUserNameOrPhone($username, $phone)
{
    return $this->where('username', $username)
                ->orWhere('client_phone', $phone)
                ->first();
}

}