HTTP APIs for Account and Password Management (2023/06/06 update)
架設環境
-
至GitHub clone 專案repository到本地資料夾,於command line輸入以下指令
git clone https://github.com/yujen77300/API-test.git
-
安裝Docker。
參考Docker官方文件,依據自己的作業系統安裝Docker engine
-
於command line, cd到專案在本地的資料夾位置,下圖為此次範例的位置
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
-
輸入以下docker-compose指令,其會自動到Docker hub pull啟動專案所需要的image,並同時run起api、db、redis三個containers。
docker-compose -f docker-compose.yml up
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
-
待出現以下畫面(約需2~3分鐘),代表已經啟動此專案,接著可以透過Postman測試api
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
API操作
除了作業要求的創建帳號、和驗證帳號密碼兩個API之外,另外設計取得使用者帳號和刪除使用者帳號等API,讓使用者更方便做測試,以下分別介紹各API之實作方法。
1. Create Account
使用者必須輸入username和password,規則如下
- 帳號至少3碼,至多32碼
- 密碼至少8碼,至多32碼,且須包含至少一個大寫字母,一個小寫字母和一個數字。
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
(密碼9碼,但未包含小寫英文字母,因此出現錯誤)
如帳號已存在,出現以下錯誤
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
如輸入成功畫面如下
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
使用者密碼經過雜湊和加鹽(2023/06/06 更新)
可登入MySQL 查看使用者密碼是否經故雜湊
- 用
docker ps
查詢MySQL的Container ID
- 輸入
docker exec -it <<Container ID>> mysql -u user
,進入資料庫
- 輸入密碼 1qaz@WSX
- 依序輸入sql指令,
use senaoapi
、select * from users
- 確認密碼已經過雜湊
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
2. Verify Account and Password
此API為驗證使用者帳號密碼,當同一個帳號輸入密碼超過五次,會鎖定一分鐘不能再嘗試輸入密碼。
如帳號未存在,出現以下錯誤
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
如帳號存在,密碼輸入錯誤會出現以下畫面
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
同一個帳號輸入超過五次會鎖定一分鐘
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
驗證成功之畫面
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
3. Get all users
取得目前所有使用者的資訊
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
4. Get specific user
根據id 取得特定使用者的資訊
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
5. Delete user
根據id 刪除使用者的資訊
刪除id=2的使用者
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
再檢視全部的使用者,確定id=2的使用者已經被刪除
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Reference
- API document