Skip to content
Snippets Groups Projects
Commit f00cf069 authored by llaffont's avatar llaffont
Browse files

Correction auth. md5

parent a3a9fef9
Branches
Tags
No related merge requests found
......@@ -63,29 +63,28 @@ class ZendAfi_Auth extends Zend_Auth {
$adapters = $this->getOrderedAdaptersForLoginPassword($login, $password);
foreach ($adapters as $authAdapter) {
$authAdapter->setIdentity($login);
$authAdapter->setCredential($password);
if (!$this->authenticate($authAdapter)->isValid()) {
$authAdapter->setCredential($this->md5_base64($this->_credential));
if (!$this->authenticate($authAdapter)->isValid())
continue;
$result = $this->authenticate($authAdapter);
if (!$result->isValid()) {
$authAdapter->setCredential($this->md5_base64($login));
$result = $this->authenticate($authAdapter);
if (!$result->isValid()) continue;
}
$this->getStorage()->write($authAdapter->getResultObject());
$this->getStorage()->write($result);
return true;
}
return false;
}
public function md5_base64 ( $data )
{
public function md5_base64 ( $data ) {
return preg_replace('/=+$/','',base64_encode(pack('H*',md5($data))));
}
public function logUser($user) {
$this->getStorage()->write($user->toStdClass());
return $this;
......
......@@ -31,16 +31,15 @@ class AuthSessionNamespaceTest extends PHPUnit_Framework_TestCase {
* @test
*/
public function validAuthenticationInMd5ShouldRedirect() {
$zendAuth = new ZendAfi_Auth();
assertTrue($zendAuth->authenticateLoginPassword('sysadm','adminPassword',[new Mock_Adapter()]));
$zendAuth = ZendAfi_Auth::getInstance();
$this->assertTrue($zendAuth->authenticateLoginPassword('sysadm','adminPassword',[new Mock_ZendAfi_Auth_MD5_Adapter()]));
}
}
class Mock_Adapter implements Zend_Auth_Adapter_Interface {
class Mock_ZendAfi_Auth_MD5_Adapter implements Zend_Auth_Adapter_Interface {
public function setIdentity($identity) {
$this->_identity = $identity;
return $this;
......@@ -58,9 +57,10 @@ class Mock_Adapter implements Zend_Auth_Adapter_Interface {
public function authenticate() {
if ($this->_credential == 'M9h/02RRb2YEEk/Mdv3SeQ')
return true;
if ($this->_credential == '4Mvw5i0DeW8x2kcJloK3Kw')
return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $this->_identity);
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND, $this->_identity);
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment