package orm

import (
	"crypto/sha1"
	"encoding/base64"
	"fmt"
	"strings"
)

type Credential struct {
	Name            string
	Surname         string
	Username        string
	Password        string
	Email           string
	TelephoneNumber string
}

func (c *Credential) sanitize(s string) string {
	r := strings.NewReplacer("'", "", "-", "", " ", "")
	return strings.ToLower(r.Replace(s))
}

func (c *Credential) GenerateUsername() string {
	return strings.Join([]string{c.sanitize(c.Name), c.sanitize(c.Surname)}, ".")
}

func (c *Credential) GenerateSaltedPassword(password string) string {
	bs := sha1.Sum([]byte(password + "salt"))
	str := base64.StdEncoding.EncodeToString(append(bs[:], []byte("salt")...))
	return fmt.Sprintf("%s", str)
}
