From 120421b3af57904bb024c9bcb8b10b7b57d11a0d Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Thu, 21 Jan 2021 14:10:13 +0100 Subject: [PATCH] Replaced the generation of the appointment hash with the use of CodeIgniter's random_string method, in order to avoid collisions (#986). --- application/models/Appointments_model.php | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/application/models/Appointments_model.php b/application/models/Appointments_model.php index 9866d350..a757636c 100644 --- a/application/models/Appointments_model.php +++ b/application/models/Appointments_model.php @@ -24,6 +24,7 @@ class Appointments_model extends EA_Model { { parent::__construct(); $this->load->helper('data_validation'); + $this->load->helper('string'); } /** @@ -153,7 +154,7 @@ class Appointments_model extends EA_Model { protected function insert($appointment) { $appointment['book_datetime'] = date('Y-m-d H:i:s'); - $appointment['hash'] = $this->generate_hash(); + $appointment['hash'] = random_string('alnum', 12); if ( ! $this->db->insert('appointments', $appointment)) { @@ -163,20 +164,6 @@ class Appointments_model extends EA_Model { return (int)$this->db->insert_id(); } - /** - * Generate a unique hash for the given appointment data. - * - * This method uses the current date-time to generate a unique hash string that is later used to identify this - * appointment. Hash is needed when the email is send to the user with an edit link. - * - * @return string Returns the unique appointment hash. - */ - public function generate_hash() - { - $current_date = new DateTime(); - return md5($current_date->getTimestamp()); - } - /** * Update an existing appointment record in the database. *