tlm-login-server/internal/shared/hash-password.go

23 lines
491 B
Go
Raw Permalink Normal View History

2023-12-06 23:25:34 +01:00
package shared
import (
"fmt"
"golang.org/x/crypto/bcrypt"
"log/slog"
)
func HashPassword(password string) []byte {
passwordbytes := []byte(password)
// Hashing the password with the default cost of 10
passwordhash, err := bcrypt.GenerateFromPassword(passwordbytes, bcrypt.DefaultCost)
if err != nil {
slog.Error("Can't hash password")
}
fmt.Println(fmt.Sprintf("Hash: %v", passwordhash))
fmt.Println(fmt.Sprintf("Hashlength: %v", len(passwordhash)))
return passwordhash
}