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