This commit is contained in:
josh 2024-05-07 08:11:11 -04:00
parent 5b97b753ed
commit b2c03ce6ae
1 changed files with 14 additions and 3 deletions

17
main.go
View File

@ -2,8 +2,10 @@ package main
import ( import (
"crypto" "crypto"
"crypto/rand"
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"io"
"log" "log"
"net/http" "net/http"
"os" "os"
@ -182,8 +184,17 @@ func modifyPasswordFile(email, password string) bool {
func createPasswordEntry(email, password string) string { func createPasswordEntry(email, password string) string {
c := crypto.SHA512.New() c := crypto.SHA512.New()
c.Write([]byte(password)) c.Write([]byte(password))
hash := c.Sum(nil) // hash := c.Sum(nil)
str := base64.StdEncoding.EncodeToString(hash) salt := getSalt()
str := base64.StdEncoding.EncodeToString([]byte(string(c.Sum(nil)) + salt))
return fmt.Sprintf("%s|{SHA512-CRYPT}$6$%s", email, str) 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)
}