![](/img/trans.png)
[英]PHP Verifying passwords using password_verify and password_hash
[英]using php password_hash passwords with freeradius
我有一個數據庫,其中包含使用用於其他幾個應用程序的password_hash加密的用戶名和密碼。
我想重復使用這些密碼來使用freeradius(用於wifi訪問)對用戶進行身份驗證。
我將FreeRADIUS版本3.0.15用於主機x86_64-pc-linux-gnu,該主機建於2017年7月28日在06:41:27 Ubuntu 16.04服務器上的FreeRADIUS版本3.0.15。 客戶是Unifi AP PRO。
我從默認安裝開始,對配置的更改最少。 為了進行測試,我在用戶中添加了一個帶有明文用戶名和密碼的用戶。 該用戶工作。
在啟用網站/默認的網站中,我在授權部分中添加了
update control {Auth-type := "/usr/bin/php -f /etc/freeradius/php/checkpasswd.php'%{User-Name}' '%{User-Password}'"}
在授權部分的開頭。 checkpasswd.php的相關部分是
//arguments ophalen
$username_radius = $argv[1];
$password_radius = $argv[2];
//wachtwoorden opzoeken in de databank
$query = $conn->prepare('SELECT passwordHash FROM gebruikers WHERE username = :username');
$query->bindParam(':username', $username_radius);
$query->execute();
$row_count = $query->rowCount();
if ($row_count != 1){
echo 'Reject';
}
else {
//is de hash van het radiuswachtwoord gelijk aan de hash in de databank?
$rs = $query->fetchAll();
$passwordHash = $rs[0][0];
if (password_verify($password_radius,$passwordHash)) {
echo 'Accept';
}
else {
echo 'Reject';
}
(對荷蘭語的評論很抱歉)基本上,密碼匹配時會說“接受”,其他所有情況下都說“拒絕”。
我了解我需要使用TTLS / PAP才能看到密碼。 但是密碼永遠不會在我的服務器上終止。 我用freeradius -X得到以下輸出
(0) Received Access-Request Id 18 from 10.1.8.99:55827 to 192.168.2.32:1812 length 157
(0) User-Name = "krog"
(0) NAS-Identifier = "24a43cb081ea"
(0) NAS-Port = 0
(0) Called-Station-Id = "36-A4-3C-B1-81-EA:ritaexam"
(0) Calling-Station-Id = "48-45-20-FB-4B-31"
(0) Framed-MTU = 1400
(0) NAS-Port-Type = Wireless-802.11
(0) Connect-Info = "CONNECT 0Mbps 802.11b"
(0) EAP-Message = 0x02660009016b726f67
(0) Message-Authenticator = 0xfa1433a62a8b77ea794a62ac47f8320d
(0) # Executing section authorize from file /etc/freeradius/sites-enabled/default
(0) authorize {
(0) update control {
(0) EXPAND /usr/bin/php -f /etc/freeradius/php/checkpasswd.php '%{User-Name}' '%{User-Password}'
(0) --> /usr/bin/php -f /etc/freeradius/php/checkpasswd.php 'krog' ''
(0) } # update control = fail
(0) } # authorize = fail
(0) Using Post-Auth-Type Reject
(0) # Executing group from file /etc/freeradius/sites-enabled/default
(0) Post-Auth-Type REJECT {
(0) attr_filter.access_reject: EXPAND %{User-Name}
(0) attr_filter.access_reject: --> krog
(0) attr_filter.access_reject: Matched entry DEFAULT at line 11
(0) [attr_filter.access_reject] = updated
(0) eap: Request was previously rejected, inserting EAP-Failure
(0) eap: Sending EAP Failure (code 4) ID 102 length 4
(0) [eap] = updated
(0) policy remove_reply_message_if_eap {
(0) if (&reply:EAP-Message && &reply:Reply-Message) {
(0) if (&reply:EAP-Message && &reply:Reply-Message) -> FALSE
(0) else {
(0) [noop] = noop
(0) } # else = noop
(0) } # policy remove_reply_message_if_eap = noop
(0) } # Post-Auth-Type REJECT = updated
(0) Delaying response for 1.000000 seconds
Waking up in 0.3 seconds.
Waking up in 0.6 seconds.
(0) Sending delayed response
(0) Sent Access-Reject Id 18 from 192.168.2.32:1812 to 10.1.8.99:55827 length 44
(0) EAP-Message = 0x04660004
(0) Message-Authenticator = 0x00000000000000000000000000000000
如您所見,用戶密碼在通信中不存在。 我發現各種帖子都提到這應該起作用。 我在某處缺少明顯的東西嗎?
感謝您的見解。 公園
改變
update control {Auth-type := "/usr/bin/php -f /etc/freeradius/php/checkpasswd.php'%{User-Name}' '%{User-Password}'"}
至
update control {Auth-type := `/usr/bin/php -f /etc/freeradius/php/checkpasswd.php '%{User-Name}' '%{User-Password}'`}
為我修復了錯誤(使用`代替“”)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.