encode() public static method

Encodes the data with username and password to create the proper response. Returns an array containing the username and encoded response.
public static encode ( string $username, string $password, array $data = [] ) : array
$username string Username to authenticate with
$password string Password to authenticate with
$data array Params needed to hash the response
return array
Beispiel #1
0
 public function testDigestHeader()
 {
     $username = '******';
     $password = '******';
     $nc = '00000001';
     $cnonce = md5(time());
     $user = md5("gwoo:app:li3");
     $nonce = "4bca0fbca7bd0:{$nc}:{$cnonce}:auth";
     $req = md5("GET:/http_auth");
     $hash = md5("{$user}:{$nonce}:{$req}");
     $data = array('realm' => 'app', 'method' => 'GET', 'uri' => '/http_auth', 'qop' => 'auth', 'nonce' => '4bca0fbca7bd0', 'opaque' => 'd3fb67a7aa4d887ec4bf83040a820a46');
     $data = Auth::encode($username, $password, $data);
     $header = Auth::header($data);
     $this->assertPattern('/Digest/', $header);
     preg_match('/response="(.*?)"/', $header, $matches);
     list($match, $response) = $matches;
     $expected = $hash;
     $result = $response;
     $this->assertEqual($expected, $result);
 }