@@ -16,15 +16,25 @@ var _ server.Authenticator = &UserPassAuthenticator{}
1616// UserPassAuthenticator checks the provided auth string against a map of username/password pairs.
1717// The format of the auth string must be "username:password".
1818type UserPassAuthenticator struct {
19- Users map [string ]string
19+ users map [string ]string
20+ }
21+
22+ func NewUserPassAuthenticator (users map [string ]string ) * UserPassAuthenticator {
23+ // Usernames are case-insensitive, as they are already lowercased by viper.
24+ // Lowercase it again on our own to make it explicit.
25+ lcUsers := make (map [string ]string , len (users ))
26+ for user , pass := range users {
27+ lcUsers [strings .ToLower (user )] = pass
28+ }
29+ return & UserPassAuthenticator {users : lcUsers }
2030}
2131
2232func (a * UserPassAuthenticator ) Authenticate (addr net.Addr , auth string , tx uint64 ) (ok bool , id string ) {
2333 u , p , ok := splitUserPass (auth )
2434 if ! ok {
2535 return false , ""
2636 }
27- rp , ok := a .Users [u ]
37+ rp , ok := a .users [u ]
2838 if ! ok || rp != p {
2939 return false , ""
3040 }
@@ -36,5 +46,6 @@ func splitUserPass(auth string) (user, pass string, ok bool) {
3646 if len (rs ) != 2 {
3747 return "" , "" , false
3848 }
39- return rs [0 ], rs [1 ], true
49+ // Usernames are case-insensitive
50+ return strings .ToLower (rs [0 ]), rs [1 ], true
4051}
0 commit comments