🎨jwt的secret每个用户不同
This commit is contained in:
@@ -4,7 +4,9 @@ import (
|
||||
"fmt"
|
||||
"gitee.ltd/lxh/logger/log"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
"github.com/mojocn/base64Captcha"
|
||||
"time"
|
||||
"wireguard-ui/component"
|
||||
"wireguard-ui/http/param"
|
||||
"wireguard-ui/http/response"
|
||||
@@ -71,15 +73,16 @@ func (LoginApi) Login(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
secret := component.JWT().GenerateSecret(p.Password, uuid.NewString(), time.Now().Local().String())
|
||||
// 生成token
|
||||
token, expireAt, err := component.JWT().GenerateToken(user.Id, utils.Hash().SHA256(p.Password))
|
||||
token, expireAt, err := component.JWT().GenerateToken(user.Id, secret)
|
||||
if err != nil {
|
||||
log.Errorf("用户[%s]生成token失败: %v", user.Account, err.Error())
|
||||
response.R(c).FailedWithError("登陆失败!")
|
||||
return
|
||||
}
|
||||
|
||||
c.Writer.Header().Set("X-TOKEN", utils.Hash().SHA256(p.Password))
|
||||
c.Writer.Header().Set("X-TOKEN", secret)
|
||||
response.R(c).OkWithData(map[string]any{
|
||||
"token": token,
|
||||
"type": "Bearer",
|
||||
|
Reference in New Issue
Block a user