| 14 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
#指派命名空間爲 qbpwcf
|
|
|
4 |
namespace qbpwcf;
|
|
|
5 |
|
|
|
6 |
#匯入外部套件
|
|
|
7 |
include("../allInOne.php");
|
|
|
8 |
|
|
|
9 |
/*
|
|
|
10 |
|
|
|
11 |
#提示目前測試的項目
|
|
|
12 |
echo"<hr>authenticate::simpleAuthenticate - testCase 1<br>";
|
|
|
13 |
|
|
|
14 |
#建立驗證碼
|
|
|
15 |
$_SESSION["password"]="password";
|
|
|
16 |
|
|
|
17 |
#涵式說明:
|
|
|
18 |
#用來檢查 $_SESSION['password'] 是否存在以及其值是否正確
|
|
|
19 |
#回傳結果:
|
|
|
20 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
21 |
#$result["passed"],是否驗證通過,"true"為驗證通過,"false"為驗證不通過.
|
|
|
22 |
#$result["function"],當前執行的函數名稱.
|
|
|
23 |
#$result["error"],錯誤訊息陣列.
|
|
|
24 |
#必填的參數:
|
|
|
25 |
$conf["password"]="password";#是驗證碼的內容應該要等於什麼才是對的。
|
|
|
26 |
var_dump(authenticate::simpleAuthenticate($conf));
|
|
|
27 |
unset($password);
|
|
|
28 |
|
|
|
29 |
#註銷驗證碼
|
|
|
30 |
unset($_SESSION["password"]);
|
|
|
31 |
|
|
|
32 |
*/
|
|
|
33 |
|
|
|
34 |
/*
|
|
|
35 |
|
|
|
36 |
#提示目前測試的項目
|
|
|
37 |
echo"<hr>authenticate::sessionAuthenticate - testCase 1<br>";
|
|
|
38 |
|
|
|
39 |
#建立驗證碼
|
|
|
40 |
$_SESSION["password"]="password";
|
|
|
41 |
|
|
|
42 |
#涵式說明:
|
|
|
43 |
#用來檢查 $_SESSION['password'] 是否存在以及其值是否正確
|
|
|
44 |
#必填的參數:
|
|
|
45 |
$conf["failLocation"]="http://www.nttu.edu.tw";#是當驗證失敗時要轉址到的位置
|
|
|
46 |
$conf["password"]="password";#是驗證碼的內容應該要等於什麼才是對的。
|
|
|
47 |
var_dump(authenticate::sessionAuthenticate($conf));
|
|
|
48 |
unset($conf);
|
|
|
49 |
|
|
|
50 |
*/
|
|
|
51 |
|
|
|
52 |
/*
|
|
|
53 |
|
|
|
54 |
#提示目前測試的項目
|
|
|
55 |
echo"<hr>authenticate::sessionAuthenticate - testCase 2<br>";
|
|
|
56 |
|
|
|
57 |
unset($_SESSION['password']);
|
|
|
58 |
|
|
|
59 |
#涵式說明:
|
|
|
60 |
#用來檢查 $_SESSION['password'] 是否存在以及其值是否正確
|
|
|
61 |
#必填的參數:
|
|
|
62 |
$conf["failLocation"]="http://www.nttu.edu.tw";#是當驗證失敗時要轉址到的位置
|
|
|
63 |
$conf["password"]="password";#是驗證碼的內容應該要等於什麼才是對的。
|
|
|
64 |
var_dump(authenticate::sessionAuthenticate($conf));
|
|
|
65 |
unset($conf);
|
|
|
66 |
|
|
|
67 |
*/
|
|
|
68 |
|
|
|
69 |
/*
|
|
|
70 |
|
|
|
71 |
#提示目前測試的項目
|
|
|
72 |
echo"<hr>authenticate::sessionAuthenticate - testCase 3<br>";
|
|
|
73 |
|
|
|
74 |
$_SESSION['password']="123";
|
|
|
75 |
|
|
|
76 |
#涵式說明:
|
|
|
77 |
#用來檢查 $_SESSION['password'] 是否存在以及其值是否正確
|
|
|
78 |
#必填的參數:
|
|
|
79 |
$conf["failLocation"]="http://www.nttu.edu.tw";#是當驗證失敗時要轉址到的位置
|
|
|
80 |
$conf["password"]="password";#是驗證碼的內容應該要等於什麼才是對的。
|
|
|
81 |
var_dump(authenticate::sessionAuthenticate($conf));
|
|
|
82 |
unset($conf);
|
|
|
83 |
|
|
|
84 |
*/
|
|
|
85 |
|
|
|
86 |
/*
|
|
|
87 |
|
|
|
88 |
#提示目前測試的項目
|
|
|
89 |
echo"<hr>authenticate::checkUserGroupAuthorities - testCase 1<br>";
|
|
|
90 |
|
|
|
91 |
#宣告使用者名稱
|
|
|
92 |
$_SESSION["username"]="root";
|
|
|
93 |
|
|
|
94 |
#函式說明:
|
|
|
95 |
#檢查session裏面的使用者資訊是否在會員清單裏面,
|
|
|
96 |
#該會員所屬的羣組是否具有權限瀏覽該子功能頁面
|
|
|
97 |
#目標資料庫裏面必須有名爲member作爲儲存會員資料的資料表。
|
|
|
98 |
#目標資料庫裏面必須有名爲userGroupAuthorities作爲儲存羣組資料的資料表
|
|
|
99 |
#回傳的參數:
|
|
|
100 |
#無.
|
|
|
101 |
#必填寫的參數:
|
|
|
102 |
$conf["thisSubSystemName"]="phplib";#爲該子系統的名稱,若該羣組所能瀏覽的子系統裏面有該名稱,則通過驗證。
|
|
|
103 |
$conf["dbName"]="test";#爲指定的資料庫名稱,欲選擇的資料庫名稱
|
|
|
104 |
$conf["dbPassword"]="dolbyhometheater";#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
105 |
#可省略的參數:
|
|
|
106 |
#$conf["dbAddress"]="localhost";#爲mysql-Server的位置,預設爲 "localhost"
|
|
|
107 |
#$conf["dbAccount"]="root";#爲用於連入mysql-Server時要使用的帳號,預設爲 "root"
|
|
|
108 |
#$conf["selectedDataTableName"]["member"]="member";#儲存會員資料的資料表,預設爲 "member"
|
|
|
109 |
#$conf["selectedDataTableName"]["userGroup"]="userGroupAuthorties";#儲存羣組資料的資,預設爲 "userGroupAuthorities"
|
|
|
110 |
var_dump(authenticate::checkUserGroupAuthorities($conf));
|
|
|
111 |
unset($conf);
|
|
|
112 |
|
|
|
113 |
*/
|
|
|
114 |
|
|
|
115 |
/*
|
|
|
116 |
|
|
|
117 |
#提示目前測試的項目
|
|
|
118 |
echo"<hr>authenticate::checkUserGroupAuthorities - testCase 2<br>";
|
|
|
119 |
|
|
|
120 |
#宣告使用者名稱
|
|
|
121 |
$_SESSION["username"]="guest";
|
|
|
122 |
|
|
|
123 |
#函式說明:
|
|
|
124 |
#檢查session裏面的使用者資訊是否在會員清單裏面,
|
|
|
125 |
#該會員所屬的羣組是否具有權限瀏覽該子功能頁面
|
|
|
126 |
#目標資料庫裏面必須有名爲member作爲儲存會員資料的資料表。
|
|
|
127 |
#目標資料庫裏面必須有名爲userGroupAuthorities作爲儲存羣組資料的資料表
|
|
|
128 |
#回傳的參數:
|
|
|
129 |
#無.
|
|
|
130 |
#必填寫的參數:
|
|
|
131 |
$conf["thisSubSystemName"]="phplib";#爲該子系統的名稱,若該羣組所能瀏覽的子系統裏面有該名稱,則通過驗證。
|
|
|
132 |
$conf["dbName"]="test";#爲指定的資料庫名稱,欲選擇的資料庫名稱
|
|
|
133 |
$conf["dbPassword"]="dolbyhometheater";#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
134 |
#可省略的參數:
|
|
|
135 |
#$conf["dbAddress"]="localhost";#爲mysql-Server的位置,預設爲 "localhost"
|
|
|
136 |
#$conf["dbAccount"]="root";#爲用於連入mysql-Server時要使用的帳號,預設爲 "root"
|
|
|
137 |
#$conf["selectedDataTableName"]["member"]="member";#儲存會員資料的資料表,預設爲 "member"
|
|
|
138 |
#$conf["selectedDataTableName"]["userGroup"]="userGroupAuthorties";#儲存羣組資料的資,預設爲 "userGroupAuthorities"
|
|
|
139 |
var_dump(authenticate::checkUserGroupAuthorities($conf));
|
|
|
140 |
unset($conf);
|
|
|
141 |
|
|
|
142 |
*/
|
|
|
143 |
|
|
|
144 |
/*
|
|
|
145 |
|
|
|
146 |
#提示目前測試的項目
|
|
|
147 |
echo"<hr>authenticate::checkUserGroupAuthorities - testCase 3<br>";
|
|
|
148 |
|
|
|
149 |
#宣告使用者名稱
|
|
|
150 |
$_SESSION["username"]="unExist";
|
|
|
151 |
|
|
|
152 |
#函式說明:
|
|
|
153 |
#檢查session裏面的使用者資訊是否在會員清單裏面,
|
|
|
154 |
#該會員所屬的羣組是否具有權限瀏覽該子功能頁面
|
|
|
155 |
#目標資料庫裏面必須有名爲member作爲儲存會員資料的資料表。
|
|
|
156 |
#目標資料庫裏面必須有名爲userGroupAuthorities作爲儲存羣組資料的資料表
|
|
|
157 |
#回傳的參數:
|
|
|
158 |
#無.
|
|
|
159 |
#必填寫的參數:
|
|
|
160 |
$conf["thisSubSystemName"]="phplib";#爲該子系統的名稱,若該羣組所能瀏覽的子系統裏面有該名稱,則通過驗證。
|
|
|
161 |
$conf["dbName"]="test";#爲指定的資料庫名稱,欲選擇的資料庫名稱
|
|
|
162 |
$conf["dbPassword"]="dolbyhometheater";#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
163 |
#可省略的參數:
|
|
|
164 |
#$conf["dbAddress"]="localhost";#爲mysql-Server的位置,預設爲 "localhost"
|
|
|
165 |
#$conf["dbAccount"]="root";#爲用於連入mysql-Server時要使用的帳號,預設爲 "root"
|
|
|
166 |
#$conf["selectedDataTableName"]["member"]="member";#儲存會員資料的資料表,預設爲 "member"
|
|
|
167 |
#$conf["selectedDataTableName"]["userGroup"]="userGroupAuthorties";#儲存羣組資料的資,預設爲 "userGroupAuthorities"
|
|
|
168 |
var_dump(authenticate::checkUserGroupAuthorities($conf));
|
|
|
169 |
unset($conf);
|
|
|
170 |
|
|
|
171 |
*/
|
|
|
172 |
|
|
|
173 |
/*
|
|
|
174 |
|
|
|
175 |
#分隔線
|
|
|
176 |
echo"<hr>authenticate::validationCode - testCase 1<br>";
|
|
|
177 |
|
|
|
178 |
#涵式說明:
|
|
|
179 |
#建立以圖片(PNG格式)呈現的驗證碼
|
|
|
180 |
#回傳的解果:
|
|
|
181 |
#$result["status"],執行是否成功。"true"代表執行成功;"false"代表執行失敗
|
|
|
182 |
#$result["error"],錯誤訊息
|
|
|
183 |
#$result["randNumberWord"],傳驗證碼的內容
|
|
|
184 |
#$result["imgAddress"],圖片的位置與名稱
|
|
|
185 |
#必填的參數
|
|
|
186 |
$conf["imgAddressAndName"]="img/test";#爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生。
|
|
|
187 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
188 |
$conf["fileArgu"]=__FILE__;
|
|
|
189 |
#可省略的參數:
|
|
|
190 |
#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
|
|
|
191 |
$conf["num"]="5";
|
|
|
192 |
#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
|
|
|
193 |
#$conf["disableImg"]="true";
|
|
|
194 |
#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"
|
|
|
195 |
$conf["imgToData"]="false";
|
|
|
196 |
var_dump(authenticate::validationCode($conf));
|
|
|
197 |
unset($conf);
|
|
|
198 |
|
|
|
199 |
#涵式說明:
|
|
|
200 |
#放置可以套用css樣式的圖片
|
|
|
201 |
#回傳的結果:
|
|
|
202 |
#$result,印出圖片的語法。
|
|
|
203 |
#必填的參數:
|
|
|
204 |
$conf["position"]="img/test.png";#圖片位置
|
|
|
205 |
#可省略的參數:
|
|
|
206 |
#$conf["alt"]="";#若沒有圖片要用什麼文字顯示。
|
|
|
207 |
#$conf["class"]="";#要套用的css樣式類別名稱。
|
|
|
208 |
var_dump(img::show($conf));
|
|
|
209 |
unset($conf);
|
|
|
210 |
|
|
|
211 |
*/
|
|
|
212 |
|
|
|
213 |
/*
|
|
|
214 |
|
|
|
215 |
#分隔線
|
|
|
216 |
echo"<hr>authenticate::validationCode - testCase 2<br>";
|
|
|
217 |
|
|
|
218 |
#涵式說明:
|
|
|
219 |
#建立以圖片(PNG格式)呈現的驗證碼
|
|
|
220 |
#回傳的解果:
|
|
|
221 |
#$result["status"],執行是否成功。"true"代表執行成功;"false"代表執行失敗
|
|
|
222 |
#$result["error"],錯誤訊息
|
|
|
223 |
#$result["randNumberWord"],傳驗證碼的內容
|
|
|
224 |
#$result["imgAddress"],圖片的位置與名稱
|
|
|
225 |
#必填的參數
|
|
|
226 |
$conf["imgAddressAndName"]="img/test";#爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生。
|
|
|
227 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
228 |
$conf["fileArgu"]=__FILE__;
|
|
|
229 |
#可省略的參數:
|
|
|
230 |
#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
|
|
|
231 |
$conf["num"]="5";
|
|
|
232 |
#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
|
|
|
233 |
$conf["disableImg"]="true";
|
|
|
234 |
var_dump(authenticate::validationCode($conf));
|
|
|
235 |
unset($conf);
|
|
|
236 |
|
|
|
237 |
*/
|
|
|
238 |
|
|
|
239 |
/*
|
|
|
240 |
|
|
|
241 |
#分隔線
|
|
|
242 |
echo"<hr>authenticate::validationCode - testCase 3<br>";
|
|
|
243 |
|
|
|
244 |
#涵式說明:
|
|
|
245 |
#建立以圖片(PNG格式)呈現的驗證碼
|
|
|
246 |
#回傳的解果:
|
|
|
247 |
#$result["status"],執行是否成功。"true"代表執行成功;"false"代表執行失敗
|
|
|
248 |
#$result["error"],錯誤訊息
|
|
|
249 |
#$result["randNumberWord"],傳驗證碼的內容
|
|
|
250 |
#$result["imgAddress"],圖片的位置與名稱
|
|
|
251 |
#必填的參數
|
|
|
252 |
$conf["imgAddressAndName"]="img/test";#爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生。
|
|
|
253 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
254 |
$conf["fileArgu"]=__FILE__;
|
|
|
255 |
#可省略的參數:
|
|
|
256 |
#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
|
|
|
257 |
$conf["num"]="5";
|
|
|
258 |
#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
|
|
|
259 |
#$conf["disableImg"]="true";
|
|
|
260 |
var_dump(authenticate::validationCode($conf));
|
|
|
261 |
unset($conf);
|
|
|
262 |
|
|
|
263 |
*/
|
|
|
264 |
|
|
|
265 |
/*
|
|
|
266 |
|
|
|
267 |
#分隔線
|
|
|
268 |
echo"<hr>authenticate::validationCode - testCase 4<br>";
|
|
|
269 |
|
|
|
270 |
#涵式說明:
|
|
|
271 |
#建立以圖片(PNG格式)呈現的驗證碼
|
|
|
272 |
#回傳的解果:
|
|
|
273 |
#$result["status"],執行是否成功。"true"代表執行成功;"false"代表執行失敗
|
|
|
274 |
#$result["error"],錯誤訊息
|
|
|
275 |
#$result["randNumberWord"],傳驗證碼的內容
|
|
|
276 |
#$result["imgAddress"],圖片的位置與名稱
|
|
|
277 |
#必填的參數
|
|
|
278 |
$conf["imgAddressAndName"]="img/test";#爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生。
|
|
|
279 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
280 |
$conf["fileArgu"]=__FILE__;
|
|
|
281 |
#可省略的參數:
|
|
|
282 |
#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
|
|
|
283 |
$conf["num"]="4";
|
|
|
284 |
#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
|
|
|
285 |
$conf["disableImg"]="true";
|
|
|
286 |
#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"
|
|
|
287 |
$conf["imgToData"]="false";
|
|
|
288 |
#$conf["class"],字串,圖片要套用的css樣式類別.
|
|
|
289 |
#$conf["class"]="";
|
|
|
290 |
#$conf["content"],字串陣列,允許的亂數陣列內容,預設爲(1~9 and A~Z).
|
|
|
291 |
$conf["content"]=array("0","1","2","3","4","5","6","7","8","9");
|
|
|
292 |
var_dump(authenticate::validationCode($conf));
|
|
|
293 |
unset($conf);
|
|
|
294 |
|
|
|
295 |
*/
|
|
|
296 |
|
|
|
297 |
/*
|
|
|
298 |
|
|
|
299 |
#分隔線與函數名稱
|
|
|
300 |
echo"<hr>authenticate::enCodeStr - testCase 1<br>";
|
|
|
301 |
|
|
|
302 |
#涵式說明:
|
|
|
303 |
#加密字串,可以用的方法有sha1,md5,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串.
|
|
|
304 |
#回傳結果:
|
|
|
305 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
306 |
#$result["function"],當前執行的函數名稱.
|
|
|
307 |
#$result["content"],加密後的結果.
|
|
|
308 |
#$result["error"],錯誤訊息陣列.
|
|
|
309 |
#必填參數:
|
|
|
310 |
#$conf["enCodeStr"],"字串",要加密的字串.
|
|
|
311 |
$conf["enCodeStr"]="str";
|
|
|
312 |
#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"兩種,前者較耗時但安全,後者較快但較不安全.
|
|
|
313 |
$conf["enCodeType"]="sha1";
|
|
|
314 |
#可省略參數:
|
|
|
315 |
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
|
|
|
316 |
$conf["sha1Raw"]="false";
|
|
|
317 |
#參考資料來源:
|
|
|
318 |
#sha1=>http://php.net/manual/en/function.sha1.php
|
|
|
319 |
#md5=>http://php.net/manual/en/function.md5.php
|
|
|
320 |
var_dump(authenticate::enCodeStr($conf));
|
|
|
321 |
unset($conf);
|
|
|
322 |
|
|
|
323 |
#涵式說明:
|
|
|
324 |
#加密字串,可以用的方法有sha1,md5,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串.
|
|
|
325 |
#回傳結果:
|
|
|
326 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
327 |
#$result["function"],當前執行的函數名稱.
|
|
|
328 |
#$result["content"],加密後的結果.
|
|
|
329 |
#$result["error"],錯誤訊息陣列.
|
|
|
330 |
#必填參數:
|
|
|
331 |
#$conf["enCodeStr"],"字串",要加密的字串.
|
|
|
332 |
$conf["enCodeStr"]="str";
|
|
|
333 |
#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"兩種,前者較耗時但安全,後者較快但較不安全.
|
|
|
334 |
$conf["enCodeType"]="sha1";
|
|
|
335 |
#可省略參數:
|
|
|
336 |
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
|
|
|
337 |
$conf["sha1Raw"]="true";
|
|
|
338 |
#參考資料來源:
|
|
|
339 |
#sha1=>http://php.net/manual/en/function.sha1.php
|
|
|
340 |
#md5=>http://php.net/manual/en/function.md5.php
|
|
|
341 |
var_dump(authenticate::enCodeStr($conf));
|
|
|
342 |
unset($conf);
|
|
|
343 |
|
|
|
344 |
#涵式說明:
|
|
|
345 |
#加密字串,可以用的方法有sha1,md5,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串.
|
|
|
346 |
#回傳結果:
|
|
|
347 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
348 |
#$result["function"],當前執行的函數名稱.
|
|
|
349 |
#$result["content"],加密後的結果.
|
|
|
350 |
#$result["error"],錯誤訊息陣列.
|
|
|
351 |
#必填參數:
|
|
|
352 |
#$conf["enCodeStr"],"字串",要加密的字串.
|
|
|
353 |
$conf["enCodeStr"]="str";
|
|
|
354 |
#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"兩種,前者較耗時但安全,後者較快但較不安全.
|
|
|
355 |
$conf["enCodeType"]="md5";
|
|
|
356 |
#可省略參數:
|
|
|
357 |
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
|
|
|
358 |
#$conf["sha1Raw"]="false";
|
|
|
359 |
#參考資料來源:
|
|
|
360 |
#sha1=>http://php.net/manual/en/function.sha1.php
|
|
|
361 |
#md5=>http://php.net/manual/en/function.md5.php
|
|
|
362 |
var_dump(authenticate::enCodeStr($conf));
|
|
|
363 |
unset($conf);
|
|
|
364 |
|
|
|
365 |
#涵式說明:
|
|
|
366 |
#加密字串,可以用的方法有sha1,md5,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串.
|
|
|
367 |
#回傳結果:
|
|
|
368 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
369 |
#$result["function"],當前執行的函數名稱.
|
|
|
370 |
#$result["content"],加密後的結果.
|
|
|
371 |
#$result["error"],錯誤訊息陣列.
|
|
|
372 |
#必填參數:
|
|
|
373 |
#$conf["enCodeStr"],"字串",要加密的字串.
|
|
|
374 |
$conf["enCodeStr"]="str";
|
|
|
375 |
#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"兩種,前者較耗時但安全,後者較快但較不安全.
|
|
|
376 |
$conf["enCodeType"]="p_hash";
|
|
|
377 |
#可省略參數:
|
|
|
378 |
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
|
|
|
379 |
#$conf["sha1Raw"]="false";
|
|
|
380 |
#參考資料來源:
|
|
|
381 |
#sha1=>http://php.net/manual/en/function.sha1.php
|
|
|
382 |
#md5=>http://php.net/manual/en/function.md5.php
|
|
|
383 |
$p_hashed_str=authenticate::enCodeStr($conf);
|
|
|
384 |
unset($conf);
|
|
|
385 |
var_dump($p_hashed_str);
|
|
|
386 |
|
|
|
387 |
#涵式說明:
|
|
|
388 |
#加密字串,可以用的方法有sha1,md5,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串.
|
|
|
389 |
#回傳結果:
|
|
|
390 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
391 |
#$result["function"],當前執行的函數名稱.
|
|
|
392 |
#$result["content"],加密後的結果.
|
|
|
393 |
#$result["error"],錯誤訊息陣列.
|
|
|
394 |
#必填參數:
|
|
|
395 |
#$conf["enCodeStr"],"字串",要加密的字串.
|
|
|
396 |
$conf["enCodeStr"]="str";
|
|
|
397 |
#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"兩種,前者較耗時但安全,後者較快但較不安全.
|
|
|
398 |
$conf["enCodeType"]="p_hash";
|
|
|
399 |
#可省略參數:
|
|
|
400 |
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
|
|
|
401 |
#$conf["sha1Raw"]="false";
|
|
|
402 |
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
|
|
|
403 |
$conf["p_hash"]=$p_hashed_str["content"];
|
|
|
404 |
#參考資料來源:
|
|
|
405 |
#sha1=>http://php.net/manual/en/function.sha1.php
|
|
|
406 |
#md5=>http://php.net/manual/en/function.md5.php
|
|
|
407 |
var_dump(authenticate::enCodeStr($conf));
|
|
|
408 |
unset($conf);
|
|
|
409 |
|
|
|
410 |
#涵式說明:
|
|
|
411 |
#加密字串,可以用的方法有sha1,md5,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串.
|
|
|
412 |
#回傳結果:
|
|
|
413 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
414 |
#$result["function"],當前執行的函數名稱.
|
|
|
415 |
#$result["content"],加密後的結果.
|
|
|
416 |
#$result["error"],錯誤訊息陣列.
|
|
|
417 |
#必填參數:
|
|
|
418 |
#$conf["enCodeStr"],"字串",要加密的字串.
|
|
|
419 |
$conf["enCodeStr"]="wrong_str";
|
|
|
420 |
#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"兩種,前者較耗時但安全,後者較快但較不安全.
|
|
|
421 |
$conf["enCodeType"]="p_hash";
|
|
|
422 |
#可省略參數:
|
|
|
423 |
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
|
|
|
424 |
#$conf["sha1Raw"]="false";
|
|
|
425 |
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
|
|
|
426 |
$conf["p_hash"]=$p_hashed_str["content"];
|
|
|
427 |
#參考資料來源:
|
|
|
428 |
#sha1=>http://php.net/manual/en/function.sha1.php
|
|
|
429 |
#md5=>http://php.net/manual/en/function.md5.php
|
|
|
430 |
var_dump(authenticate::enCodeStr($conf));
|
|
|
431 |
unset($conf);
|
|
|
432 |
|
|
|
433 |
*/
|
|
|
434 |
|
|
|
435 |
/*
|
|
|
436 |
|
|
|
437 |
#分隔線與函數名稱
|
|
|
438 |
echo"<hr>authenticate::enCodeStr - testCase 2<br>";
|
|
|
439 |
|
|
|
440 |
#涵式說明:
|
|
|
441 |
#加密字串,可以用的方法有sha1,md5,password_sha,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
|
|
|
442 |
#回傳結果:
|
|
|
443 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
444 |
#$result["function"],當前執行的函數名稱.
|
|
|
445 |
#$result["content"],加密後的結果.
|
|
|
446 |
#$result["error"],錯誤訊息陣列.
|
|
|
447 |
#$result["argu"],使用的參數.
|
|
|
448 |
#必填參數:
|
|
|
449 |
#$conf["enCodeStr"],"字串",要加密的字串.
|
|
|
450 |
$conf["enCodeStr"]="fh829fh84fh2489fh8299813239";
|
|
|
451 |
#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"與"p_hash"3種,"sha1"較耗時,"md5"較快,"p_hash"適用於密碼加密.
|
|
|
452 |
$conf["enCodeType"]="p_hash";
|
|
|
453 |
#可省略參數:
|
|
|
454 |
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
|
|
|
455 |
#$conf["sha1Raw"]="false";
|
|
|
456 |
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
|
|
|
457 |
#$conf["p_hash"]="";
|
|
|
458 |
#參考資料來源:
|
|
|
459 |
#sha1=>http://php.net/manual/en/function.sha1.php
|
|
|
460 |
#md5=>http://php.net/manual/en/function.md5.php
|
|
|
461 |
#password_hash=>http://php.net/manual/en/function.password-hash.php
|
|
|
462 |
#password_verify=>http://php.net/manual/en/function.password-verify.php
|
|
|
463 |
$enCodeStr=authenticate::enCodeStr($conf);
|
|
|
464 |
unset($conf);
|
|
|
465 |
|
|
|
466 |
var_dump($enCodeStr);
|
|
|
467 |
|
|
|
468 |
#涵式說明:
|
|
|
469 |
#加密字串,可以用的方法有sha1,md5,password_sha,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
|
|
|
470 |
#回傳結果:
|
|
|
471 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
472 |
#$result["function"],當前執行的函數名稱.
|
|
|
473 |
#$result["content"],加密後的結果.
|
|
|
474 |
#$result["error"],錯誤訊息陣列.
|
|
|
475 |
#$result["argu"],使用的參數.
|
|
|
476 |
#必填參數:
|
|
|
477 |
#$conf["enCodeStr"],"字串",要加密的字串.
|
|
|
478 |
$conf["enCodeStr"]="fh829fh84fh2489fh8299813239";
|
|
|
479 |
#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"與"p_hash"3種,"sha1"較耗時,"md5"較快,"p_hash"適用於密碼加密.
|
|
|
480 |
$conf["enCodeType"]="p_hash";
|
|
|
481 |
#可省略參數:
|
|
|
482 |
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
|
|
|
483 |
#$conf["sha1Raw"]="false";
|
|
|
484 |
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
|
|
|
485 |
$conf["p_hash"]=$enCodeStr["content"];
|
|
|
486 |
#參考資料來源:
|
|
|
487 |
#sha1=>http://php.net/manual/en/function.sha1.php
|
|
|
488 |
#md5=>http://php.net/manual/en/function.md5.php
|
|
|
489 |
#password_hash=>http://php.net/manual/en/function.password-hash.php
|
|
|
490 |
#password_verify=>http://php.net/manual/en/function.password-verify.php
|
|
|
491 |
$enCodeStr=authenticate::enCodeStr($conf);
|
|
|
492 |
unset($conf);
|
|
|
493 |
|
|
|
494 |
var_dump($enCodeStr);
|
|
|
495 |
|
|
|
496 |
*/
|
|
|
497 |
|
|
|
498 |
/*
|
|
|
499 |
|
|
|
500 |
#分隔線與函數名稱
|
|
|
501 |
echo"<hr>authenticate::enCodeStr - testCase 3<br>";
|
|
|
502 |
|
|
|
503 |
$原文="密碼";
|
|
|
504 |
|
|
|
505 |
#印出原文
|
|
|
506 |
echo "原文:".$原文."<br>";
|
|
|
507 |
|
|
|
508 |
#取得 tls key
|
|
|
509 |
#函式說明:
|
|
|
510 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
511 |
#回傳的變數說明:
|
|
|
512 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
|
|
|
513 |
#$result["error"],錯誤訊息提示.
|
|
|
514 |
#$result["warning"],警告訊息.
|
|
|
515 |
#$result["function"],當前執行的函數名稱.
|
|
|
516 |
#$result["fileContent"],爲檔案的內容陣列.
|
|
|
517 |
#$result["lineCount"],爲檔案內容總共的行數.
|
|
|
518 |
#$result["fullContent"],為檔案的完整內容.
|
|
|
519 |
#$result["base64data"],為檔案的base64內容.
|
|
|
520 |
#$result["mimeType"],為檔案的mime type.
|
|
|
521 |
#必填的參數:
|
|
|
522 |
#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
|
|
|
523 |
$conf["filePositionAndName"]="/etc/pki/tls/private/private.key";
|
|
|
524 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
525 |
$conf["fileArgu"]=__FILE__;
|
|
|
526 |
#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
|
|
|
527 |
$conf["web"]="false";
|
|
|
528 |
#參考資料:
|
|
|
529 |
#file(),取得檔案內容的行數.
|
|
|
530 |
#file=>http:#php.net/manual/en/function.file.php
|
|
|
531 |
#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
|
|
|
532 |
#filesize=>http://php.net/manual/en/function.filesize.php
|
|
|
533 |
$getFileContent=fileAccess::getFileContent($conf);
|
|
|
534 |
unset($conf);
|
|
|
535 |
|
|
|
536 |
#如果取得 tls 檔案失敗
|
|
|
537 |
if($getFileContent["status"]==="false")
|
|
|
538 |
{
|
|
|
539 |
#初始化要印出的結果
|
|
|
540 |
$result=array();
|
|
|
541 |
|
|
|
542 |
#設置執行失敗
|
|
|
543 |
$result["status"]="false";
|
|
|
544 |
|
|
|
545 |
#設置錯誤訊息
|
|
|
546 |
$result["error"]=$getFileContent;
|
|
|
547 |
|
|
|
548 |
#印出結果
|
|
|
549 |
var_dump($result);
|
|
|
550 |
|
|
|
551 |
#停止執行
|
|
|
552 |
exit;
|
|
|
553 |
|
|
|
554 |
}#if end
|
|
|
555 |
|
|
|
556 |
#tls key
|
|
|
557 |
$tlsKey=$getFileContent["fullContent"];
|
|
|
558 |
|
|
|
559 |
#涵式說明:
|
|
|
560 |
#加密字串,可以用的方法有sha1,md5,password_sha,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
|
|
|
561 |
#回傳結果:
|
|
|
562 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
563 |
#$result["function"],當前執行的函數名稱.
|
|
|
564 |
#$result["content"],加密後的結果.
|
|
|
565 |
#$result["error"],錯誤訊息陣列.
|
|
|
566 |
#$result["argu"],使用的參數.
|
|
|
567 |
#必填參數:
|
|
|
568 |
#$conf["enCodeStr"],"字串",要加密的字串.
|
|
|
569 |
$conf["enCodeStr"]=$原文;
|
|
|
570 |
#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"與"p_hash"與"aes256"4種,"sha1"較耗時,"md5"較快,"p_hash"適用於密碼加密,"aes256"是對稱式加解密.
|
|
|
571 |
$conf["enCodeType"]="aes256";
|
|
|
572 |
#可省略參數:
|
|
|
573 |
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
|
|
|
574 |
#$conf["sha1Raw"]="false";
|
|
|
575 |
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
|
|
|
576 |
#$conf["p_hash"]="";
|
|
|
577 |
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
|
|
|
578 |
$conf["keyForAes256"]=$tlsKey;
|
|
|
579 |
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
|
|
|
580 |
$conf["aes256Encode"]="true";
|
|
|
581 |
#參考資料來源:
|
|
|
582 |
#sha1=>http://php.net/manual/en/function.sha1.php
|
|
|
583 |
#md5=>http://php.net/manual/en/function.md5.php
|
|
|
584 |
#password_hash=>http://php.net/manual/en/function.password-hash.php
|
|
|
585 |
#password_verify=>http://php.net/manual/en/function.password-verify.php
|
|
|
586 |
$enCodeStr=authenticate::enCodeStr($conf);
|
|
|
587 |
unset($conf);
|
|
|
588 |
|
|
|
589 |
#如果加密出錯
|
|
|
590 |
if($enCodeStr["status"]==="false")
|
|
|
591 |
{
|
|
|
592 |
#初始化要印出的結果
|
|
|
593 |
$result=array();
|
|
|
594 |
|
|
|
595 |
#設置執行失敗
|
|
|
596 |
$result["status"]="false";
|
|
|
597 |
|
|
|
598 |
#設置錯誤訊息
|
|
|
599 |
$result["error"]=$enCodeStr;
|
|
|
600 |
|
|
|
601 |
#印出結果
|
|
|
602 |
var_dump($result);
|
|
|
603 |
|
|
|
604 |
#停止執行
|
|
|
605 |
exit;
|
|
|
606 |
|
|
|
607 |
}#if end
|
|
|
608 |
|
|
|
609 |
#取得加密後的內文
|
|
|
610 |
$密文=$enCodeStr["content"];
|
|
|
611 |
|
|
|
612 |
#印出加密後的密文
|
|
|
613 |
echo "密文:".$密文."<br>";
|
|
|
614 |
|
|
|
615 |
#涵式說明:
|
|
|
616 |
#加密字串,可以用的方法有sha1,md5,password_sha,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
|
|
|
617 |
#回傳結果:
|
|
|
618 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
619 |
#$result["function"],當前執行的函數名稱.
|
|
|
620 |
#$result["content"],加密後的結果.
|
|
|
621 |
#$result["error"],錯誤訊息陣列.
|
|
|
622 |
#$result["argu"],使用的參數.
|
|
|
623 |
#必填參數:
|
|
|
624 |
#$conf["enCodeStr"],"字串",要加密的字串.
|
|
|
625 |
$conf["enCodeStr"]=$密文;
|
|
|
626 |
#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"與"p_hash"與"aes256"4種,"sha1"較耗時,"md5"較快,"p_hash"適用於密碼加密,"aes256"是對稱式加解密.
|
|
|
627 |
$conf["enCodeType"]="aes256";
|
|
|
628 |
#可省略參數:
|
|
|
629 |
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
|
|
|
630 |
#$conf["sha1Raw"]="false";
|
|
|
631 |
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
|
|
|
632 |
#$conf["p_hash"]="";
|
|
|
633 |
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
|
|
|
634 |
$conf["keyForAes256"]=$tlsKey;
|
|
|
635 |
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
|
|
|
636 |
$conf["aes256Encode"]="false";
|
|
|
637 |
#參考資料來源:
|
|
|
638 |
#sha1=>http://php.net/manual/en/function.sha1.php
|
|
|
639 |
#md5=>http://php.net/manual/en/function.md5.php
|
|
|
640 |
#password_hash=>http://php.net/manual/en/function.password-hash.php
|
|
|
641 |
#password_verify=>http://php.net/manual/en/function.password-verify.php
|
|
|
642 |
$enCodeStr=authenticate::enCodeStr($conf);
|
|
|
643 |
unset($conf);
|
|
|
644 |
|
|
|
645 |
#如果加密出錯
|
|
|
646 |
if($enCodeStr["status"]==="false")
|
|
|
647 |
{
|
|
|
648 |
#初始化要印出的結果
|
|
|
649 |
$result=array();
|
|
|
650 |
|
|
|
651 |
#設置執行失敗
|
|
|
652 |
$result["status"]="false";
|
|
|
653 |
|
|
|
654 |
#設置錯誤訊息
|
|
|
655 |
$result["error"]=$$enCodeStr;
|
|
|
656 |
|
|
|
657 |
#印出結果
|
|
|
658 |
var_dump($result);
|
|
|
659 |
|
|
|
660 |
#停止執行
|
|
|
661 |
exit;
|
|
|
662 |
|
|
|
663 |
}#if end
|
|
|
664 |
|
|
|
665 |
#取得解密後的內文
|
|
|
666 |
$明文=$enCodeStr["content"];
|
|
|
667 |
|
|
|
668 |
#印出解密後的明文
|
|
|
669 |
echo "明文:".$明文."<br>";
|
|
|
670 |
|
|
|
671 |
#/*
|
|
|
672 |
|
|
|
673 |
#分隔線與函數名稱
|
|
|
674 |
echo"<hr>authenticate::hex2bin - testCase 1<br>";
|
|
|
675 |
|
|
|
676 |
#涵式說明:
|
|
|
677 |
#將字串變成2元碼或2元碼變成字串.
|
|
|
678 |
#回傳結果:
|
|
|
679 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
680 |
#$result["function"],當前執行的函數名稱.
|
|
|
681 |
#$result["content"],加密後的結果.
|
|
|
682 |
#$result["error"],錯誤訊息陣列.
|
|
|
683 |
#必填參數:
|
|
|
684 |
#$conf["input"],"字串",要hex或unhex的字串
|
|
|
685 |
$conf["input"]="Hello world";
|
|
|
686 |
#$conf["action"],"字串",要toBin或toStr.
|
|
|
687 |
$conf["action"]="toBin";
|
|
|
688 |
#參考資料:
|
|
|
689 |
#hex2bin=>http://php.net/manual/en/function.hex2bin.php
|
|
|
690 |
#bin2hex=>http://php.net/manual/en/function.binhex.php
|
|
|
691 |
#pack=>http://php.net/manual/en/function.pack.php
|
|
|
692 |
#備註:
|
|
|
693 |
#參數的來源不易取得,建議改成輸入字串加密成2元碼,再hex,或逆向還原成原始字串.
|
|
|
694 |
$binStr=authenticate::str2bin($conf);
|
|
|
695 |
unset($conf);
|
|
|
696 |
var_dump($binStr);
|
|
|
697 |
|
|
|
698 |
#涵式說明:
|
|
|
699 |
#將字串變成2元碼或2元碼變成字串.
|
|
|
700 |
#回傳結果:
|
|
|
701 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
702 |
#$result["function"],當前執行的函數名稱.
|
|
|
703 |
#$result["content"],加密後的結果.
|
|
|
704 |
#$result["error"],錯誤訊息陣列.
|
|
|
705 |
#必填參數:
|
|
|
706 |
#$conf["input"],"字串",要hex或unhex的字串
|
|
|
707 |
$conf["input"]=$binStr["content"];
|
|
|
708 |
#$conf["action"],"字串",要toBin或toStr.
|
|
|
709 |
$conf["action"]="toStr";
|
|
|
710 |
#參考資料:
|
|
|
711 |
#hex2bin=>http://php.net/manual/en/function.hex2bin.php
|
|
|
712 |
#bin2hex=>http://php.net/manual/en/function.binhex.php
|
|
|
713 |
#pack=>http://php.net/manual/en/function.pack.php
|
|
|
714 |
#備註:
|
|
|
715 |
#參數的來源不易取得,建議改成輸入字串加密成2元碼,再hex,或逆向還原成原始字串.
|
|
|
716 |
var_dump(authenticate::str2bin($conf));
|
|
|
717 |
unset($conf);
|
|
|
718 |
|
|
|
719 |
*/
|
|
|
720 |
|
|
|
721 |
/*
|
|
|
722 |
|
|
|
723 |
#分隔線與函數名稱
|
|
|
724 |
echo"<hr>authenticate::validUser - testCase 1<br>";
|
|
|
725 |
|
|
|
726 |
#涵式說明:
|
|
|
727 |
#驗證Linux使用者的密碼是否正確.
|
|
|
728 |
#回傳結果:
|
|
|
729 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
730 |
#$result["function"],當前執行的函數名稱.
|
|
|
731 |
#$result["error"],錯誤訊息陣列.
|
|
|
732 |
#$result["valid"],是否為存在的使用者且密碼正確.
|
|
|
733 |
#必填參數:
|
|
|
734 |
#$conf["username"],字串,要驗證的使用者名稱.
|
|
|
735 |
$conf["username"]="notExistUser";
|
|
|
736 |
#$conf["password"],字串,用於驗證使用者的密碼.
|
|
|
737 |
$conf["password"]="wrongPasswd";
|
|
|
738 |
$validUser=authenticate::validUser($conf);
|
|
|
739 |
unset($conf);
|
|
|
740 |
var_dump($validUser);
|
|
|
741 |
|
|
|
742 |
*/
|
|
|
743 |
|
|
|
744 |
/*
|
|
|
745 |
|
|
|
746 |
#分隔線與函數名稱
|
|
|
747 |
echo"<hr>authenticate::validUser - testCase 2<br>";
|
|
|
748 |
|
|
|
749 |
#涵式說明:
|
|
|
750 |
#驗證Linux使用者的密碼是否正確.
|
|
|
751 |
#回傳結果:
|
|
|
752 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
753 |
#$result["function"],當前執行的函數名稱.
|
|
|
754 |
#$result["error"],錯誤訊息陣列.
|
|
|
755 |
#$result["valid"],是否為存在的使用者且密碼正確.
|
|
|
756 |
#必填參數:
|
|
|
757 |
#$conf["username"],字串,要驗證的使用者名稱.
|
|
|
758 |
$conf["username"]="liveuser";
|
|
|
759 |
#$conf["password"],字串,用於驗證使用者的密碼.
|
|
|
760 |
$conf["password"]="wrongPasswd";
|
|
|
761 |
$validUser=authenticate::validUser($conf);
|
|
|
762 |
unset($conf);
|
|
|
763 |
var_dump($validUser);
|
|
|
764 |
|
|
|
765 |
*/
|
|
|
766 |
|
|
|
767 |
/*
|
|
|
768 |
|
|
|
769 |
#分隔線與函數名稱
|
|
|
770 |
echo"<hr>authenticate::validUser - testCase 3<br>";
|
|
|
771 |
|
|
|
772 |
#請先手動增加使用者test,且密碼為test,測試完畢後記得移除該帳號.
|
|
|
773 |
|
|
|
774 |
#涵式說明:
|
|
|
775 |
#驗證Linux使用者的密碼是否正確.
|
|
|
776 |
#回傳結果:
|
|
|
777 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
778 |
#$result["function"],當前執行的函數名稱.
|
|
|
779 |
#$result["error"],錯誤訊息陣列.
|
|
|
780 |
#$result["valid"],是否為存在的使用者且密碼正確.
|
|
|
781 |
#必填參數:
|
|
|
782 |
#$conf["username"],字串,要驗證的使用者名稱.
|
|
|
783 |
$conf["username"]="test";
|
|
|
784 |
#$conf["password"],字串,用於驗證使用者的密碼.
|
|
|
785 |
$conf["password"]="test";
|
|
|
786 |
$validUser=authenticate::validUser($conf);
|
|
|
787 |
unset($conf);
|
|
|
788 |
var_dump($validUser);
|
|
|
789 |
|
|
|
790 |
*/
|
|
|
791 |
|
|
|
792 |
/*
|
|
|
793 |
|
|
|
794 |
#分隔線與函數名稱
|
|
|
795 |
echo"<hr>authenticate::validUser - testCase 4<br>";
|
|
|
796 |
|
|
|
797 |
#請先手動增加使用者test,且密碼為test,測試完畢後記得移除該帳號.
|
|
|
798 |
|
|
|
799 |
$rewrite="false";
|
|
|
800 |
while(true)
|
|
|
801 |
{
|
|
|
802 |
#函數說明:
|
|
|
803 |
#如果在設定檔取得不了對應的數值,則改用 readLine 取得設定值.
|
|
|
804 |
#回傳結果:
|
|
|
805 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
806 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
807 |
#$result["function"],當前執行的函式名稱.
|
|
|
808 |
#$result["content"],設定值內容.
|
|
|
809 |
#必填參數:
|
|
|
810 |
#$conf["readVarName"],字串,要從設定檔取得的變數名稱.
|
|
|
811 |
$conf["readVarName"]="password";
|
|
|
812 |
#可省略參數:
|
|
|
813 |
#$conf["conf"],字串,設定檔的名稱與路徑,預設為 ".qbpwcf_tmp/cmd/getFromConf/conf.xml"
|
|
|
814 |
#$conf["conf"]=".qbpwcf_tmp/cmd/getFromConf/conf";
|
|
|
815 |
#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
|
|
|
816 |
#$conf["fileArgu"]=__FILE__;
|
|
|
817 |
#$conf["commentsArray"],字串,提示輸入內容的描述,一個元素代表一列內容,預設為 array("請輸入變數 $conf["readVarName"] 的內容").
|
|
|
818 |
$conf["commentsArray"]=array("請輸入test帳戶的密碼");
|
|
|
819 |
#$conf["forceRewrite"],字串,是否要強制覆寫設定值,"true"代表要;"false"代表不要.
|
|
|
820 |
$conf["forceRewrite"]=$rewrite;
|
|
|
821 |
$getFromConf=cmd::getFromConf($conf);
|
|
|
822 |
unset($conf);
|
|
|
823 |
|
|
|
824 |
#如果抓取設定值失敗
|
|
|
825 |
if($getFromConf["status"]=="false")
|
|
|
826 |
{
|
|
|
827 |
#debug
|
|
|
828 |
var_dump($getFromConf);
|
|
|
829 |
|
|
|
830 |
#結束程式
|
|
|
831 |
exit;
|
|
|
832 |
|
|
|
833 |
}#if end
|
|
|
834 |
|
|
|
835 |
#涵式說明:
|
|
|
836 |
#驗證Linux使用者的密碼是否正確.
|
|
|
837 |
#回傳結果:
|
|
|
838 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
839 |
#$result["function"],當前執行的函數名稱.
|
|
|
840 |
#$result["error"],錯誤訊息陣列.
|
|
|
841 |
#$result["valid"],是否為存在的使用者且密碼正確.
|
|
|
842 |
#必填參數:
|
|
|
843 |
#$conf["username"],字串,要驗證的使用者名稱.
|
|
|
844 |
$conf["username"]="test";
|
|
|
845 |
#$conf["password"],字串,用於驗證使用者的密碼.
|
|
|
846 |
$conf["password"]=$getFromConf["content"];
|
|
|
847 |
$validUser=authenticate::validUser($conf);
|
|
|
848 |
unset($conf);
|
|
|
849 |
|
|
|
850 |
#如果驗證使用者失敗
|
|
|
851 |
if($validUser["status"]=="false")
|
|
|
852 |
{
|
|
|
853 |
#debug
|
|
|
854 |
var_dump($validUser);
|
|
|
855 |
|
|
|
856 |
#結束程式
|
|
|
857 |
exit;
|
|
|
858 |
}
|
|
|
859 |
|
|
|
860 |
#如果驗證使用者成功
|
|
|
861 |
if($validUser["valid"]=="true")
|
|
|
862 |
{
|
|
|
863 |
#設置通過
|
|
|
864 |
$rewrite="false";
|
|
|
865 |
|
|
|
866 |
#跳出while
|
|
|
867 |
break;
|
|
|
868 |
}
|
|
|
869 |
|
|
|
870 |
#如果驗證用者不成功
|
|
|
871 |
else if($validUser["valid"]=="false")
|
|
|
872 |
{
|
|
|
873 |
#設置要重新輸入密碼
|
|
|
874 |
$rewrite="true";
|
|
|
875 |
}
|
|
|
876 |
}
|
|
|
877 |
|
|
|
878 |
*/
|
|
|
879 |
|
|
|
880 |
/*
|
|
|
881 |
|
|
|
882 |
#分隔線與函數名稱
|
|
|
883 |
echo"<hr>authenticate::encodePassword - testCase 1<br>";
|
|
|
884 |
|
|
|
885 |
#函式說明:
|
|
|
886 |
#用php的password_hash方法來單向加密密碼.
|
|
|
887 |
#回傳結果:
|
|
|
888 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
889 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
890 |
#$result["function"],當前執行的函式名稱.
|
|
|
891 |
#$result["content"],呼叫完WebService所得回傳結果.
|
|
|
892 |
#必填參數:
|
|
|
893 |
#無
|
|
|
894 |
#可省略參數:
|
|
|
895 |
#$conf["password"],字串,要加密的密碼.
|
|
|
896 |
#$conf["password"]="qbpwcf";
|
|
|
897 |
$conf=array();
|
|
|
898 |
$encodePassword=authenticate::encodePassword($conf);
|
|
|
899 |
unset($conf);
|
|
|
900 |
|
|
|
901 |
#如果執行失敗
|
|
|
902 |
if($encodePassword["status"]==="false"){
|
|
|
903 |
|
|
|
904 |
#印出結果
|
|
|
905 |
var_dump($encodePassword);
|
|
|
906 |
|
|
|
907 |
#結束執行
|
|
|
908 |
exit;
|
|
|
909 |
|
|
|
910 |
}#if end
|
|
|
911 |
|
|
|
912 |
#印出結果
|
|
|
913 |
var_dump($encodePassword);
|
|
|
914 |
|
|
|
915 |
*/
|
|
|
916 |
|
|
|
917 |
/*
|
|
|
918 |
|
|
|
919 |
#分隔線與函數名稱
|
|
|
920 |
echo"<hr>authenticate::validPassword - testCase 1<br>";
|
|
|
921 |
|
|
|
922 |
#函式說明:
|
|
|
923 |
#用php的password_verify方法來驗證密碼是否正確.
|
|
|
924 |
#回傳結果:
|
|
|
925 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
926 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
927 |
#$result["function"],當前執行的函式名稱.
|
|
|
928 |
#$result["content"],呼叫完WebService所得回傳結果.
|
|
|
929 |
#必填參數:
|
|
|
930 |
#$conf["input"],字串,要檢查是否正確的待驗證密碼.
|
|
|
931 |
$conf["input"]="qbpwcf";
|
|
|
932 |
#$conf["password"],字串,透過encodePassword加密後的密碼.
|
|
|
933 |
$conf["password"]="$2y$10$6bGfUY44f/AMB9Aldf6dp.iEtST8tTc2CitrVEqV4WzUF3Tie/8ua";
|
|
|
934 |
#可省略參數:
|
|
|
935 |
#無
|
|
|
936 |
$validPassword=authenticate::validPassword($conf);
|
|
|
937 |
unset($conf);
|
|
|
938 |
|
|
|
939 |
#如果執行失敗
|
|
|
940 |
if($validPassword["status"]==="false"){
|
|
|
941 |
|
|
|
942 |
#印出結果
|
|
|
943 |
var_dump($validPassword);
|
|
|
944 |
|
|
|
945 |
#結束執行
|
|
|
946 |
exit;
|
|
|
947 |
|
|
|
948 |
}#if end
|
|
|
949 |
|
|
|
950 |
#印出結果
|
|
|
951 |
var_dump($validPassword["passed"]);
|
|
|
952 |
|
|
|
953 |
*/
|
|
|
954 |
|
|
|
955 |
/*
|
|
|
956 |
|
|
|
957 |
#分隔線與函數名稱
|
|
|
958 |
echo"<hr>authenticate::validPassword - testCase 2<br>";
|
|
|
959 |
|
|
|
960 |
#函式說明:
|
|
|
961 |
#用php的password_verify方法來驗證密碼是否正確.
|
|
|
962 |
#回傳結果:
|
|
|
963 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
964 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
965 |
#$result["function"],當前執行的函式名稱.
|
|
|
966 |
#$result["content"],呼叫完WebService所得回傳結果.
|
|
|
967 |
#必填參數:
|
|
|
968 |
#$conf["input"],字串,要檢查是否正確的待驗證密碼.
|
|
|
969 |
$conf["input"]="abc";
|
|
|
970 |
#$conf["password"],字串,透過encodePassword加密後的密碼.
|
|
|
971 |
$conf["password"]="$2y$10$6bGfUY44f/AMB9Aldf6dp.iEtST8tTc2CitrVEqV4WzUF3Tie/8ua";
|
|
|
972 |
#可省略參數:
|
|
|
973 |
#無
|
|
|
974 |
$validPassword=authenticate::validPassword($conf);
|
|
|
975 |
unset($conf);
|
|
|
976 |
|
|
|
977 |
#如果執行失敗
|
|
|
978 |
if($validPassword["status"]==="false"){
|
|
|
979 |
|
|
|
980 |
#印出結果
|
|
|
981 |
var_dump($validPassword);
|
|
|
982 |
|
|
|
983 |
#結束執行
|
|
|
984 |
exit;
|
|
|
985 |
|
|
|
986 |
}#if end
|
|
|
987 |
|
|
|
988 |
#印出結果
|
|
|
989 |
var_dump($validPassword["passed"]);
|
|
|
990 |
|
|
|
991 |
*/
|
|
|
992 |
|
|
|
993 |
/*
|
|
|
994 |
|
|
|
995 |
#分隔線與函數名稱
|
|
|
996 |
echo"<hr>authenticate::gl_reCAPTCHA_client & gl_reCAPTCHA_server - testCase 1<br>";
|
|
|
997 |
|
|
|
998 |
#函式說明:
|
|
|
999 |
#產生 google reCAPTCHA 的使用者界面
|
|
|
1000 |
#回傳結果:
|
|
|
1001 |
#
|
|
|
1002 |
#必填參數:
|
|
|
1003 |
#$conf["sitekey"],字串,要用 recaptcha 的 site key.
|
|
|
1004 |
$conf["sitekey"]="6LfCWj0UAAAAAF-R04tBKWxFc3obKTuHwZsNadal";
|
|
|
1005 |
#可省略參數:
|
|
|
1006 |
#無
|
|
|
1007 |
#參考資料:
|
|
|
1008 |
#
|
|
|
1009 |
$gl_reCAPTCHA_client=authenticate::gl_reCAPTCHA_client($conf);
|
|
|
1010 |
unset($conf);
|
|
|
1011 |
|
|
|
1012 |
#如果建立 google reCAPTCHA 失敗
|
|
|
1013 |
if($gl_reCAPTCHA_client["status"]==="false"){
|
|
|
1014 |
|
|
|
1015 |
#印出結果
|
|
|
1016 |
var_dump($gl_reCAPTCHA_client);
|
|
|
1017 |
|
|
|
1018 |
}#if end
|
|
|
1019 |
|
|
|
1020 |
#印出語法
|
|
|
1021 |
var_dump($gl_reCAPTCHA_client);
|
|
|
1022 |
|
|
|
1023 |
*/
|
|
|
1024 |
|
|
|
1025 |
/*
|
|
|
1026 |
|
|
|
1027 |
echo"<hr>authenticate::gl_reCAPTCH_authCheck - testCase 1<br>";
|
|
|
1028 |
|
|
|
1029 |
#涵式說明:
|
|
|
1030 |
#檢查是否擁有透過gl_reCAPTCHA_server授權的session網址記錄.
|
|
|
1031 |
#回傳結果:
|
|
|
1032 |
#$result["status"],執行正常與否,"false"代表不正常;"true"代表正常.
|
|
|
1033 |
#$result["error"],錯誤訊息陣列.
|
|
|
1034 |
#$result["function"],函式名稱.
|
|
|
1035 |
#$result["passed"],"true"代表通過檢查,"false"代表沒有通過檢查.
|
|
|
1036 |
#必填參數:
|
|
|
1037 |
#$conf["url"],字串,要有什麼的網址才通過檢查
|
|
|
1038 |
$conf["url"]="https://169.254.1.1/~qbpwcf/samplePage/phplib/qbpwcf/testCase/authenticateT.php";
|
|
|
1039 |
$gl_reCAPTCH_authCheck=authenticate::gl_reCAPTCH_authCheck($conf);
|
|
|
1040 |
unset($conf);
|
|
|
1041 |
|
|
|
1042 |
#如果建立 google reCAPTCHA 失敗
|
|
|
1043 |
if($gl_reCAPTCH_authCheck["status"]==="false"){
|
|
|
1044 |
|
|
|
1045 |
#印出結果
|
|
|
1046 |
var_dump($gl_reCAPTCH_authCheck);
|
|
|
1047 |
|
|
|
1048 |
}#if end
|
|
|
1049 |
|
|
|
1050 |
#印出語法
|
|
|
1051 |
var_dump($gl_reCAPTCH_authCheck);
|
|
|
1052 |
|
|
|
1053 |
*/
|
|
|
1054 |
|
|
|
1055 |
/*
|
|
|
1056 |
|
|
|
1057 |
#echo"<hr>authenticate::verifyCodeAndFormData - testCase 1<br>";
|
|
|
1058 |
|
|
|
1059 |
#涵式說明:
|
|
|
1060 |
#產生亂數驗證碼或驗證亂數驗證碼與表單資料
|
|
|
1061 |
#回傳結果:
|
|
|
1062 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1063 |
#$result["error"],錯誤訊息.
|
|
|
1064 |
#$result["argu"],使用的參數.
|
|
|
1065 |
#$result["function"],當前執行的函數名稱.
|
|
|
1066 |
#$result["content"],語法.
|
|
|
1067 |
#必填參數:
|
|
|
1068 |
#$conf["fileArgu"]
|
|
|
1069 |
$conf["fileArgu"]=__FILE__;
|
|
|
1070 |
#可省略參數:
|
|
|
1071 |
#$conf["sendedName"],字串,傳送的post變數名稱,預設爲"formData".
|
|
|
1072 |
#$conf["sendedName"]="";
|
|
|
1073 |
#$conf["codeFormName"],字串,驗證碼表單的名稱,預設為"randomCode".
|
|
|
1074 |
#$conf["codeFormName"]="randomCode";
|
|
|
1075 |
#$conf["names"],字串陣列,需要處理的表單變數.
|
|
|
1076 |
#$conf["names"]=array();
|
|
|
1077 |
#備註:
|
|
|
1078 |
#建構中...
|
|
|
1079 |
$verifyCodeAndFormData=authenticate::verifyCodeAndFormData($conf);
|
|
|
1080 |
unset($conf);
|
|
|
1081 |
|
|
|
1082 |
#如果執行失敗
|
|
|
1083 |
if($verifyCodeAndFormData["status"]==="false"){
|
|
|
1084 |
|
|
|
1085 |
#印出結果
|
|
|
1086 |
var_dump($verifyCodeAndFormData);
|
|
|
1087 |
|
|
|
1088 |
#結束執行
|
|
|
1089 |
exit;
|
|
|
1090 |
|
|
|
1091 |
}#if end
|
|
|
1092 |
|
|
|
1093 |
#印出jsono
|
|
|
1094 |
echo $verifyCodeAndFormData["content"];
|
|
|
1095 |
|
|
|
1096 |
*/
|
|
|
1097 |
|
|
|
1098 |
?>
|