salt
This commit is contained in:
parent
7749102432
commit
8f5b4b921a
10
main.go
10
main.go
|
@ -186,16 +186,16 @@ 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)
|
||||||
salt := getSalt()
|
salt := base64.StdEncoding.EncodeToString(getSalt())
|
||||||
str := base64.StdEncoding.EncodeToString([]byte(string(c.Sum(nil)) + salt))
|
str := base64.StdEncoding.EncodeToString([]byte(string(c.Sum(nil))))
|
||||||
return fmt.Sprintf("%s|{SHA512-CRYPT}$6$%s", email, str)
|
return fmt.Sprintf("%s|{SHA512-CRYPT}$6$%s$%s", email, salt, str)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSalt() string {
|
func getSalt() []byte {
|
||||||
salt := make([]byte, 5)
|
salt := make([]byte, 5)
|
||||||
_, err := io.ReadFull(rand.Reader, salt)
|
_, err := io.ReadFull(rand.Reader, salt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
return string(salt)
|
return salt
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue