我想解密使用基本身份驗(yàn)證加密的用戶名和密碼。在我的客戶端應(yīng)用程序中,我有一個(gè)文件列表。如果用戶想要下載,他們將單擊指向帶有參數(shù)id(即fileId)和.php 的 PHP 文件的錨鏈接token。我有一個(gè)客戶端錨標(biāo)簽,比如<a href="http://localhost:8080/management/download.php?id=1&token=YmFsYTphYWFhYWFhYWFh"> download</a>令牌是使用以下 javascript 代碼創(chuàng)建的const token = window.btoa(username + ':' + password)文件:下載.php$fileId = $_GET['id'];$token = $_GET['token'];$filePath = getFileById($fileId);if (file_exists($filePath)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="'.basename($filePath).'"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($filePath)); readfile($filePath); exit;}我試圖從默認(rèn)值中獲取用戶名和密碼,$_SERVER['PHP_AUTH_USER']但無(wú)法獲取信息。請(qǐng)幫助我如何從令牌中解密用戶名和密碼。
1 回答

aluckdog
TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超7個(gè)贊
在 PHP 中使用base64_decode()獲取用戶名和密碼以:.
<?php
$decoded = base64_decode($_GET['token']);
list($username,$password) = explode(":",$decoded);
echo $username," ",$password;
演示: https : //3v4l.org/KKIlR
此外,這似乎不夠安全,無(wú)法像 GET 參數(shù)中那樣發(fā)送密碼(不確定此處描述的是什么密碼)。最好改為發(fā)送一個(gè)標(biāo)頭,例如Authorization: Basic YmFsYTphYWFhYWFhYWFh它實(shí)際上是一些客戶端 ID 和客戶端秘密 base-64 編碼的位置。
- 1 回答
- 0 關(guān)注
- 181 瀏覽
添加回答
舉報(bào)
0/150
提交
取消