From 2b39d116b2d7b9939eb599d33edd0673e064cb30 Mon Sep 17 00:00:00 2001 From: int2001 Date: Fri, 25 Jul 2025 10:52:27 +0000 Subject: [PATCH] Check Username for uniqueness b4 adding/editing --- application/controllers/User.php | 11 +++++++++++ application/models/User_model.php | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/application/controllers/User.php b/application/controllers/User.php index 4126dd569..abd088755 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -151,6 +151,7 @@ class User extends CI_Controller { $this->load->library('Genfunctions'); $this->form_validation->set_rules('user_name', 'Username', 'required'); + $this->form_validation->set_rules('user_name', 'Username', 'required|callback_check_username'); $this->form_validation->set_rules('user_email', 'E-mail', 'required'); $this->form_validation->set_rules('user_password', 'Password', 'required'); $this->form_validation->set_rules('user_type', 'Type', 'required'); @@ -373,6 +374,7 @@ class User extends CI_Controller { $this->load->library('Genfunctions'); $this->form_validation->set_rules('user_name', 'Username', 'required|xss_clean'); + $this->form_validation->set_rules('user_name', 'Username', 'required|callback_check_username'); $this->form_validation->set_rules('user_email', 'E-mail', 'required|xss_clean'); if($this->session->userdata('user_type') == 99) { @@ -1446,6 +1448,15 @@ class User extends CI_Controller { } } + function check_username($username) { + if (($this->session->userdata('user_name') != $username) && ($this->user_model->exists($username) > 0)) { + $this->form_validation->set_message('check_username', sprintf(__("Couldn't set account to this username. Please try another one than \"%s\"."), $username)); + return FALSE; + } else { + return TRUE; + } + } + function check_email($mail) { if (($this->session->userdata('user_email') != $mail) && ($this->user_model->exists_by_email($mail) > 0)) { $this->form_validation->set_message('check_email', sprintf(__("Couldn't set account to this email. Please try another address than \"%s\"."), $mail)); diff --git a/application/models/User_model.php b/application/models/User_model.php index bd99e45be..f08f6daef 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -19,7 +19,7 @@ class User_Model extends CI_Model { // Clean ID $clean_username = $this->security->xss_clean($username); - $this->db->where('user_name', $clean_username); + $this->db->where('upper(user_name)', strtoupper($clean_username)); $r = $this->db->get($this->config->item('auth_table')); return $r; }