fix: the bug when htpasswd has multiple creds

earlier, when you had more than one creds in htpasswd file separated by
newline, it used to only read the first cred in the file and ignore the
rest.
This commit is contained in:
Tanmay Naik 2020-06-09 17:19:01 -04:00
parent d16cbb0b10
commit 3cfb2b30a6

View File

@ -141,15 +141,16 @@ func basicAuthHandler(c *Controller) mux.MiddlewareFunc {
if err != nil {
panic(err)
}
defer f.Close()
for {
r := bufio.NewReader(f)
line, err := r.ReadString('\n')
if err != nil {
break
scanner := bufio.NewScanner(f)
for scanner.Scan() {
line := scanner.Text()
if strings.Contains(line, ":") {
tokens := strings.Split(scanner.Text(), ":")
credMap[tokens[0]] = tokens[1]
}
tokens := strings.Split(line, ":")
credMap[tokens[0]] = tokens[1]
}
}
}