題組的密碼尋回功能是以明碼方式在前台顯示出來,實務上千萬不要這麼做,這裏只是在測驗應檢人知道資料庫的應用方式。
建立密碼尋回畫面
./front/forget.php 畫面html碼
1 2 3 4 5 6 7 8 9 10 11
| <fieldset> <legend>忘記密碼</legend> <div>請輸入信箱以查詢密碼</div> <div> <input type="text" name="email" id="email"> </div> <div id="result"></div> <div> <button onclick="forget()"> </div> </fieldset>
|

撰寫ajax取回結果函式
/view/front/forgot.php
1 2 3 4 5
| function forget(){ $.get("./api/forget.php",{email:$("#email").val()},(res)=>{ $("#result").text(res) }) }
|

撰寫後端回傳密碼程式
1 2 3 4 5 6 7 8 9 10 11 12
| include_once "db.php";
$user=$User->find(['email'=>$_GET['email']]);
if(empty($user)){ echo "查無此資料"; }else{ echo "您的密碼為:".$user['pw']; }
|