You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

38 lines
816 B

// Random password
package main
import (
"crypto/rand"
"encoding/base32"
"github.com/GehirnInc/crypt/sha512_crypt"
)
func randomPassword() (password string, err error) {
randomBytes := make([]byte, 20)
_, err = rand.Read(randomBytes)
if err != nil {
return
}
password = base32.StdEncoding.EncodeToString(randomBytes)
return
}
func hashPassword(passwordToHash string) (hashedPassword string, err error) {
crypt := sha512_crypt.New()
// $6$ is for SHA512
output, err := crypt.Generate([]byte(passwordToHash), []byte("$6$ipxeplease"))
if err != nil {
return
}
hashedPassword = string(output)
return
}
func randomPasswordHashed() (password, hashedPassword string, err error) {
password, err = randomPassword()
if err != nil {
return
}
hashedPassword, err = hashPassword(password)
return
}