This commit is contained in:
josh 2024-05-07 08:27:03 -04:00
parent 7749102432
commit 8f5b4b921a
1 changed files with 5 additions and 5 deletions

10
main.go
View File

@ -186,16 +186,16 @@ func createPasswordEntry(email, password string) string {
c := crypto.SHA512.New()
c.Write([]byte(password))
// 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)
salt := base64.StdEncoding.EncodeToString(getSalt())
str := base64.StdEncoding.EncodeToString([]byte(string(c.Sum(nil))))
return fmt.Sprintf("%s|{SHA512-CRYPT}$6$%s$%s", email, salt, str)
}
func getSalt() string {
func getSalt() []byte {
salt := make([]byte, 5)
_, err := io.ReadFull(rand.Reader, salt)
if err != nil {
log.Fatal(err)
}
return string(salt)
return salt
}