File tree 2 files changed +10
-21
lines changed
2 files changed +10
-21
lines changed Original file line number Diff line number Diff line change 1
1
package models
2
2
3
+ import "strings"
4
+
3
5
type Auth struct {
4
6
Anonymous bool
5
7
Username string
@@ -18,3 +20,7 @@ func NewAuth(username, password string) Auth {
18
20
Password : password ,
19
21
}
20
22
}
23
+
24
+ func (a Auth ) Check (username , password string ) bool {
25
+ return strings .ToLower (username ) == strings .ToLower (a .Username ) && password == a .Password
26
+ }
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ package procs
2
2
3
3
import (
4
4
"fmt"
5
- "strings"
6
5
7
6
"github.com/ItsNotGoodName/smtpbridge/internal/core"
8
7
)
@@ -14,33 +13,17 @@ func AuthHTTPAnonymous(cc core.Context) bool {
14
13
}
15
14
16
15
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 ) {
18
17
return nil
19
18
}
20
19
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
30
21
}
31
22
32
23
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 ) {
34
25
return nil
35
26
}
36
27
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
46
29
}
You can’t perform that action at this time.
0 commit comments