mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-11 14:41:21 +00:00
feat(auth): make password encryption opt-in #6743
This commit is contained in:
+10
-1
@@ -40,12 +40,17 @@ var (
|
||||
)
|
||||
|
||||
func GetPasswordEncryptionKey(c *gin.Context) {
|
||||
if !common.PasswordLoginEncryptionEnabled {
|
||||
common.ApiSuccess(c, gin.H{"enabled": false})
|
||||
return
|
||||
}
|
||||
keyID, publicKey := common.PasswordEncryptionPublicKey()
|
||||
if keyID == "" || publicKey == "" {
|
||||
common.ApiErrorI18n(c, i18n.MsgDatabaseError)
|
||||
return
|
||||
}
|
||||
common.ApiSuccess(c, gin.H{
|
||||
"enabled": true,
|
||||
"kid": keyID,
|
||||
"public_key": publicKey,
|
||||
})
|
||||
@@ -64,7 +69,11 @@ func Login(c *gin.Context) {
|
||||
}
|
||||
username := loginRequest.Username
|
||||
password := loginRequest.Password
|
||||
if loginRequest.PasswordEncrypted != "" {
|
||||
if common.PasswordLoginEncryptionEnabled {
|
||||
if loginRequest.PasswordEncrypted == "" || loginRequest.EncryptionKeyID == "" {
|
||||
common.ApiErrorI18n(c, i18n.MsgInvalidParams)
|
||||
return
|
||||
}
|
||||
password, err = common.DecryptPassword(loginRequest.PasswordEncrypted, loginRequest.EncryptionKeyID)
|
||||
if err != nil {
|
||||
common.ApiErrorI18n(c, i18n.MsgUserUsernameOrPasswordError)
|
||||
|
||||
Reference in New Issue
Block a user