Zend Framework 2參考Zend\Authentication(摘要式身份驗證)

Zend Framework 2參考Zend\Authentication(摘要式身份驗證)

介紹

摘要式身份驗證是HTTP身份驗證的方法,提升了基自己份驗證時提供的方式進行身份驗證,而無需在網絡上以明文傳送口令。
這個適配器的認證包含了摘要式身份驗證的基本要素的連續字符串文本:

  • 用戶名,像」joe.user
  • 區域,像」Administrative Area
  • 用冒號分割進行MD5哈希化的用戶名,區域,密碼

上面的選項用冒號分割,像下面這樣(密碼用」somePassword「表示):php

1
someUser:Some Realm:fde17b91c3a510ecbaf7dbd37f59d4f8

細節

摘要身份驗證適配器,Zend\Authentication\Adapter\Digest,須要多個輸入參數:數組

  • 文件名 – 文件名進行認證查詢
  • 區域 – 摘要式身份驗證區域
  • 用戶名 – 摘要式身份驗證的用戶
  • 密碼 – 用戶區域的密碼

這些參數必須預先調用authenticate()網絡

身份

摘要身份驗證適配器返回一個Zend\Authentication\Result對象,這個對象包含了realm username鍵的數組。在authenticate()調用以前設置了這些數組值。ide

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use Zend\Authentication\Adapter\Digest  as AuthAdapter;
 
$adapter new AuthAdapter( $filename ,
                            $realm ,
                            $username ,
                            $password );
 
$result $adapter ->authenticate();
 
$identity $result ->getIdentity();
 
print_r( $identity );
 
/*
Array
(
     [realm] => Some Realm
     [username] => someUser
)
*/
相關文章
相關標籤/搜索