public function testApr1() { $val = 'asdfgh'; $salt = md5($val); $result = ezcAuthenticationMath::apr1($val, $salt); $hashFromHtpasswd = '$apr1$a152e841$qDLZqN37bdBiQGa7SnsIM1'; $this->assertEquals($result, $hashFromHtpasswd); $this->assertEquals(true, ezcAuthenticationMath::apr1($val, $hashFromHtpasswd) === $hashFromHtpasswd); }
/** * Runs the filter and returns a status code when finished. * * @param ezcAuthenticationPasswordCredentials $credentials Authentication credentials * @return int */ public function run($credentials) { $fh = fopen($this->file, 'r'); $found = false; while ($line = fgets($fh)) { if (substr($line, 0, strlen($credentials->id) + 1) === $credentials->id . ':') { $found = true; break; } } fclose($fh); if ($found) { $parts = explode(':', $line); $hashFromFile = trim($parts[1]); if (substr($hashFromFile, 0, 6) === '$apr1$') { $password = $this->options->plain ? ezcAuthenticationMath::apr1($credentials->password, $hashFromFile) : '$apr1$' . $credentials->password; } elseif (substr($hashFromFile, 0, 5) === '{SHA}') { $password = $this->options->plain ? '{SHA}' . base64_encode(pack('H40', sha1($credentials->password))) : '{SHA}' . $credentials->password; } else { $password = $this->options->plain ? crypt($credentials->password, $hashFromFile) : $credentials->password; } if ($password === $hashFromFile) { return self::STATUS_OK; } else { return self::STATUS_PASSWORD_INCORRECT; } } return self::STATUS_USERNAME_INCORRECT; }