> For the complete documentation index, see [llms.txt](https://iwallet.jittagornp.me/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://iwallet.jittagornp.me/installation/two-factor-authen.md).

# Two-Factor Authentication

![](/files/-MiGInyWhKsFNDFHPsnC)

## 1. สร้าง Secret Key

ใช้คำสั่ง `googleauth-gen` โดยพิมพ์คำสั่ง Docker run ดังนี้

```bash
$ docker run --rm -v $PWD:/iwallet ghcr.io/jittagornp/iwallet googleauth-gen
```

ตัวอย่าง

```bash
$ docker run --rm -v $PWD:/iwallet ghcr.io/jittagornp/iwallet googleauth-gen

Generating QR code and config...
Output QR code file "google-authenticator/qr.png"
Output config file "google-authenticator/config.json"

$ cat google-authenticator/config.json
{
  "secretKey" : "ZGYLMHUQUN4ZWNKKTSSFARNCGNGJTJON",
  "account" : "iwallet",
  "issuer" : "iWallet",
  "barcode" : "otpauth://totp/iWallet%3Aiwallet?secret=ZGYLMHUQUN4ZWNKKTSSFARNCGNGJTJON&issuer=iWallet",
  "qrcodeFile" : "qr.png"
}
```

**หมายเหตุ**

* เวอร์ชัน Free เปลี่ยน Repository จาก  `ghcr.io/jittagornp/iwallet` เป็น `jittagornp/iwallet`

ระบบจะสร้างไฟล์ขึ้นมาให้ 2 ไฟล์ได้แก่

* QR Code (google-authenticator/qr.png)
* Config File (google-authenticator/config.json)

![](/files/-Mhmz29GTm17HWAVC5Lh)

## 2. Mobile

ในฝั่งของ Mobile ให้เปิดโปรแกรม Google Authenticator &#x20;

จากนั้นให้ทำการ Scan QR Code ที่เราได้สร้างไว้ในข้อ 1 ก็เป็นอันเสร็จเรียบร้อย&#x20;

![](/files/-Mhn0sIla5JGQ6Ul7YIR)

ถ้าไม่สามารถ Scan QR Code ได้ ให้ใช้ Secret Key จากไฟล์ config.json ในข้อ 1 มากรอกเองดังนี้

![](/files/-Mhn1945Nt3xhXqYnCCh)

## 3. การ Run Bot

ตอน Run bot ให้เพิ่ม Environment Variable `IWALLET_GOOGLEAUTH_SECRET_KEY` นี้เข้าไปด้วย&#x20;

```bash
$ docker run -d \
  -p 8080:8080 \
  -v $PWD:/iwallet \
  -e IWALLET_DATABASE_USERNAME="<YOUR_DATABASE_USERNAME>" \
  -e IWALLET_DATABASE_PASSWORD="<YOUR_DATABASE_PASSWORD>" \
  -e IWALLET_APP_SECRET="<YOUR_APP_SECRET>" \
  -e IWALLET_ALLOW_DOMAINS="<YOUR_DOMAIN_NAME>"
  -e IWALLET_GOOGLEAUTH_SECRET_KEY="<YOUR_GOOGLEAUTH_SECRET_KEY>" \
  --restart=always \
  --name iwallet ghcr.io/jittagornp/iwallet
```

`IWALLET_GOOGLEAUTH_SECRET_KEY` กำหนดค่าเป็น Secret Key ที่ได้จากข้อ 1
