Skip to content

Commit 82d1153

Browse files
fix: SMTP and HTTP auth
1 parent cad941a commit 82d1153

File tree

2 files changed

+10
-21
lines changed

2 files changed

+10
-21
lines changed

internal/models/auth.go

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package models
22

3+
import "strings"
4+
35
type Auth struct {
46
Anonymous bool
57
Username string
@@ -18,3 +20,7 @@ func NewAuth(username, password string) Auth {
1820
Password: password,
1921
}
2022
}
23+
24+
func (a Auth) Check(username, password string) bool {
25+
return strings.ToLower(username) == strings.ToLower(a.Username) && password == a.Password
26+
}

internal/procs/auth.go

+4-21
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package procs
22

33
import (
44
"fmt"
5-
"strings"
65

76
"github.com/ItsNotGoodName/smtpbridge/internal/core"
87
)
@@ -14,33 +13,17 @@ func AuthHTTPAnonymous(cc core.Context) bool {
1413
}
1514

1615
func AuthHTTPLogin(cc core.Context, username, password string) error {
17-
if AuthHTTPAnonymous(cc) {
16+
if cc.Config.AuthHTTP.Anonymous || cc.Config.AuthHTTP.Check(username, password) {
1817
return nil
1918
}
2019

21-
if strings.ToLower(username) != cc.Config.AuthHTTP.Username {
22-
return ErrorLogin
23-
}
24-
25-
if strings.ToLower(password) != cc.Config.AuthHTTP.Password {
26-
return ErrorLogin
27-
}
28-
29-
return nil
20+
return ErrorLogin
3021
}
3122

3223
func AuthSMTPLogin(cc core.Context, username, password string) error {
33-
if cc.Config.AuthSMTP.Username == "" && cc.Config.AuthSMTP.Password == "" {
24+
if cc.Config.AuthSMTP.Anonymous || cc.Config.AuthSMTP.Check(username, password) {
3425
return nil
3526
}
3627

37-
if strings.ToLower(username) != cc.Config.AuthSMTP.Username {
38-
return ErrorLogin
39-
}
40-
41-
if strings.ToLower(password) != cc.Config.AuthSMTP.Password {
42-
return ErrorLogin
43-
}
44-
45-
return nil
28+
return ErrorLogin
4629
}

0 commit comments

Comments
 (0)