]> Cypherpunks.ru repositories - gocheese.git/blobdiff - passwd.go
Split pretty huge gocheese.go
[gocheese.git] / passwd.go
index 852192f8b7ea898cb54d7ea3a4e912f884e13bc9..f6760d2910091bdcbefc301d2d85f29ae471512e 100644 (file)
--- a/passwd.go
+++ b/passwd.go
@@ -19,13 +19,43 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 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)
        }