From 9a0cc4b139ee3d240ab6a723f6bd31c5d1aa2be0 Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch>
Date: Thu, 29 Aug 2024 16:09:51 +0200
Subject: [PATCH] user auth interface and ldap: php8 only; added variable
 types; use short array syntax

---
 .../deployment/classes/userauth.interface.php | 17 +++++--
 .../classes/userauth.ldap.class.php           | 44 +++++++++++++------
 2 files changed, 43 insertions(+), 18 deletions(-)

diff --git a/public_html/deployment/classes/userauth.interface.php b/public_html/deployment/classes/userauth.interface.php
index 83a4a3ac..3bd5c837 100644
--- a/public_html/deployment/classes/userauth.interface.php
+++ b/public_html/deployment/classes/userauth.interface.php
@@ -1,14 +1,23 @@
 <?php
 /**
  * interface for user authentication
+ * 
  * @author axel.hahn@iml.unibe.ch
+ * 
+ * Axel <axel.hahn@unibe.ch>
+ * 2024-08-29  Axel php8 only; added variable types; use short array syntax
  */
-interface iUserAuth {
+interface iUserAuth
+{
 
     /**
-     * verify if a given user and password combination is correct
+     * Verify if a given user and password combination is correct
+     * 
+     * @param string  $sUser      username
+     * @param string  $sPassword  password
+     * @return boolean
      */
-    public function authenticate($sUser, $sPassword);
-    
+    public function authenticate(string $sUser, string $sPassword): bool;
+
 
 }
\ No newline at end of file
diff --git a/public_html/deployment/classes/userauth.ldap.class.php b/public_html/deployment/classes/userauth.ldap.class.php
index 07c440ad..a8e5bc1c 100644
--- a/public_html/deployment/classes/userauth.ldap.class.php
+++ b/public_html/deployment/classes/userauth.ldap.class.php
@@ -8,42 +8,58 @@ require_once("ldap.class.php");
  * implements userauth interface
  * 
  * @author hahn
+ * 
+ * Axel <axel.hahn@unibe.ch>
+ * 2024-08-29  Axel php8 only; added variable types
  */
-class userauthLdap implements iUserAuth {
+class userauthLdap implements iUserAuth
+{
 
     /**
      * object for ldap actions
      * @var object
      */
-    private $_oLdap=false;
-    
+    private object $_oLdap;
+
     // ----------------------------------------------------------------------
     // 
     // ----------------------------------------------------------------------
-    public function __construct() {
+
+    /**
+     * Constructor
+     */
+    public function __construct()
+    {
         global $aConfig;
-        $this->_oLdap=new imlldap($aConfig['auth']['ldap']);
-        
+        $this->_oLdap = new imlldap($aConfig['auth']['ldap']);
+
         // first test of ldap connection
         // $this->_oLdap->debugOn();
         $this->_oLdap->connect();
-        return true;
     }
-    
-    public function __destruct() {
+
+    /**
+     * Destructor
+     * Close ldap connection
+     */
+    public function __destruct()
+    {
         $this->_oLdap->close();
     }
-    
+
     // ----------------------------------------------------------------------
     // implementation
     // ----------------------------------------------------------------------
+
     /**
-     * verify if a given user and password combination is correct
-     * @param string   $sUser      username
-     * @param password $sPassword  password
+     * Verify if a given user and password combination is correct
+     * 
+     * @param string  $sUser      username
+     * @param string  $sPassword  password
      * @return boolean
      */
-    public function authenticate($sUser, $sPassword){
+    public function authenticate(string $sUser, string $sPassword): bool
+    {
         return $this->_oLdap->verifyPassword($sUser, $sPassword);
     }
 
-- 
GitLab