lithium\net\http\Auth::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.

Parameters

  • string $username

    Username to authenticate with

  • string $password

    Password to authenticate with

  • array $data

    Params needed to hash the response

Returns

array

Source

	public static function encode($username, $password, $data = []) {
		if (isset($data['nonce'])) {
			$defaults = [
				'realm' => 'app', 'method' => 'GET', 'uri' => '/', 'qop' => null,
				'cnonce' => md5(time()), 'nc' => static::$nc
			];
			$data = array_filter($data) + $defaults;
			$part1 = md5("{$username}:{$data['realm']}:{$password}");
			$part2 = "{$data['nonce']}:{$data['nc']}:{$data['cnonce']}:{$data['qop']}";
			$part3 = md5($data['method'] . ':' . $data['uri']);
			$response = md5("{$part1}:{$part2}:{$part3}");
			return compact('username', 'response') + $data;
		}
		$response = base64_encode("{$username}:{$password}");
		return compact('username', 'response');
	}