authhtpasswd : return the only detail available -> email

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3015 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2016-09-01 10:18:32 +00:00
parent 3873935e3a
commit 748eef3eab

View File

@@ -12,6 +12,9 @@ class authhtpasswd extends auth
/** The .htpasswd file to use for authentication */ /** The .htpasswd file to use for authentication */
public $htpasswdFile; public $htpasswdFile;
/** The details to return if the user is authenticated */
private $details = null;
public function connect () public function connect ()
{ {
if (! file_exists ($this->htpasswdFile)) if (! file_exists ($this->htpasswdFile))
@@ -43,8 +46,12 @@ class authhtpasswd extends auth
$cryptedPassword = substr (strstr ($line, ':'), 1); $cryptedPassword = substr (strstr ($line, ':'), 1);
if ($user === $email) if ($user === $email)
{ {
if (substr ($cryptedPassword, 0, 6) === '$apr1$')
throw new \Exception (dgettext ("domframework",
"Invalid format of password"), 500);
if (crypt ($password, $cryptedPassword) !== $cryptedPassword) if (crypt ($password, $cryptedPassword) !== $cryptedPassword)
throw new Exception ("Bad password for '$email'", 401); throw new Exception ("Bad password for '$email'", 401);
$this->details = array ("email"=>$email);
return TRUE; return TRUE;
} }
} }
@@ -54,9 +61,7 @@ class authhtpasswd extends auth
/** Return all the parameters recorded for the authenticate user */ /** Return all the parameters recorded for the authenticate user */
public function getdetails () public function getdetails ()
{ {
throw new Exception (dgettext ("domframework", return $this->details;
"The details can't be provided by HTPasswd file"),
404);
} }
/** Method to change the password /** Method to change the password