X-Git-Url: http://www.git.cypherpunks.ru/?p=gocheese.git;a=blobdiff_plain;f=passwd.go;h=f6760d2910091bdcbefc301d2d85f29ae471512e;hp=b13a342c92835a25dfc67f968dc956dfb54ae3d1;hb=b036ee436eb9bd8889734232a22d3f24be5c9ee2;hpb=8f8381ed1ab5b4ce972dfc6c205b157a3233c76f diff --git a/passwd.go b/passwd.go index b13a342..f6760d2 100644 --- a/passwd.go +++ b/passwd.go @@ -19,18 +19,51 @@ along with this program. If not, see . package main import ( + "errors" "io/ioutil" "log" + "os" "strings" ) +var passwords map[string]Auther = make(map[string]Auther) + +type Auther interface { + Auth(password string) bool +} + +func strToAuther(verifier string) (string, Auther, error) { + st := strings.SplitN(verifier, "$", 3) + if len(st) != 3 || st[0] != "" { + return "", nil, errors.New("invalid verifier structure") + } + algorithm := st[1] + var auther Auther + var err error + switch algorithm { + case "argon2i": + auther, err = parseArgon2i(st[2]) + case "sha256": + auther, err = parseSHA256(st[2]) + default: + err = errors.New("unknown hashing algorithm") + } + return algorithm, auther, err +} + func refreshPasswd() { passwd, err := ioutil.ReadFile(*passwdPath) + if os.IsNotExist(err) { + return + } if err != nil { log.Fatal(err) } passwordsNew := make(map[string]Auther) for i, credentials := range strings.Split(strings.TrimRight(string(passwd), "\n"), "\n") { + if len(credentials) == 0 || strings.HasPrefix(credentials, "#") { + continue + } splitted := strings.Split(credentials, ":") if len(splitted) != 2 { log.Fatalf("%s:%d: Wrong login:password format", *passwdPath, i)