diff --git a/main.go b/main.go index c462cc6..86fd9d5 100644 --- a/main.go +++ b/main.go @@ -2,8 +2,10 @@ package main import ( "crypto" + "crypto/rand" "encoding/base64" "fmt" + "io" "log" "net/http" "os" @@ -182,8 +184,17 @@ func modifyPasswordFile(email, password string) bool { func createPasswordEntry(email, password string) string { c := crypto.SHA512.New() c.Write([]byte(password)) - hash := c.Sum(nil) - str := base64.StdEncoding.EncodeToString(hash) - + // hash := c.Sum(nil) + salt := getSalt() + str := base64.StdEncoding.EncodeToString([]byte(string(c.Sum(nil)) + salt)) return fmt.Sprintf("%s|{SHA512-CRYPT}$6$%s", email, str) } + +func getSalt() string { + salt := make([]byte, 32) + _, err := io.ReadFull(rand.Reader, salt) + if err != nil { + log.Fatal(err) + } + return string(salt) +}