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 (
"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)
}