feat(auth): encrypt password login transport

Closes #6743
This commit is contained in:
CaIon
2026-08-29 20:11:36 +08:00
parent 98d50d5383
commit b80d633cf5
10 changed files with 372 additions and 12 deletions
+23 -2
View File
@@ -28,8 +28,10 @@ import (
)
type LoginRequest struct {
Username string `json:"username"`
Password string `json:"password"`
Username string `json:"username"`
Password string `json:"password"`
PasswordEncrypted string `json:"password_encrypted"`
EncryptionKeyID string `json:"encryption_key_id"`
}
var (
@@ -37,6 +39,18 @@ var (
errOriginalPasswordFail = errors.New("original password is incorrect")
)
func GetPasswordEncryptionKey(c *gin.Context) {
keyID, publicKey := common.PasswordEncryptionPublicKey()
if keyID == "" || publicKey == "" {
common.ApiErrorI18n(c, i18n.MsgDatabaseError)
return
}
common.ApiSuccess(c, gin.H{
"kid": keyID,
"public_key": publicKey,
})
}
func Login(c *gin.Context) {
if !common.PasswordLoginEnabled {
common.ApiErrorI18n(c, i18n.MsgUserPasswordLoginDisabled)
@@ -50,6 +64,13 @@ func Login(c *gin.Context) {
}
username := loginRequest.Username
password := loginRequest.Password
if loginRequest.PasswordEncrypted != "" {
password, err = common.DecryptPassword(loginRequest.PasswordEncrypted, loginRequest.EncryptionKeyID)
if err != nil {
common.ApiErrorI18n(c, i18n.MsgUserUsernameOrPasswordError)
return
}
}
if username == "" || password == "" {
common.ApiErrorI18n(c, i18n.MsgInvalidParams)
return