package utils import ( "crypto/sha256" "encoding/hex" "fmt" "github.com/google/uuid" ) func PasswordEncrypt(password string) string { salt := uuid.New().String()[24:] password = password + salt shaRes := hex.EncodeToString(sha256.New().Sum([]byte(password))) encryptPwd := fmt.Sprintf("ncov$%s$%s", shaRes[0:24], salt) return encryptPwd } func PasswordCompare(plaintext string, ciphertext string) (ok bool) { salt := ciphertext[30:] password := plaintext + salt shaRes := hex.EncodeToString(sha256.New().Sum([]byte(password))) return shaRes[0:24] == ciphertext[5:29] }