From 748eef3eaba883f370a8d8e7053a2f6dbb586654 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Thu, 1 Sep 2016 10:18:32 +0000 Subject: [PATCH] authhtpasswd : return the only detail available -> email git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3015 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- authhtpasswd.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/authhtpasswd.php b/authhtpasswd.php index d0f224e..3c31ceb 100644 --- a/authhtpasswd.php +++ b/authhtpasswd.php @@ -12,6 +12,9 @@ class authhtpasswd extends auth /** The .htpasswd file to use for authentication */ public $htpasswdFile; + /** The details to return if the user is authenticated */ + private $details = null; + public function connect () { if (! file_exists ($this->htpasswdFile)) @@ -43,8 +46,12 @@ class authhtpasswd extends auth $cryptedPassword = substr (strstr ($line, ':'), 1); if ($user === $email) { + if (substr ($cryptedPassword, 0, 6) === '$apr1$') + throw new \Exception (dgettext ("domframework", + "Invalid format of password"), 500); if (crypt ($password, $cryptedPassword) !== $cryptedPassword) throw new Exception ("Bad password for '$email'", 401); + $this->details = array ("email"=>$email); return TRUE; } } @@ -54,9 +61,7 @@ class authhtpasswd extends auth /** Return all the parameters recorded for the authenticate user */ public function getdetails () { - throw new Exception (dgettext ("domframework", - "The details can't be provided by HTPasswd file"), - 404); + return $this->details; } /** Method to change the password