salt
This commit is contained in:
parent
5b97b753ed
commit
b2c03ce6ae
17
main.go
17
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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue