gitstack

demo/acme-pay code browser

468 B Go 18 lines 2024-01-16 · ff9d4e8 raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package auth

import (
	"crypto/sha256"
	"encoding/hex"
)

// HashPassword returns a SHA-256 hex digest of the given password.
// In production use bcrypt; this is the demo implementation.
func HashPassword(password string) string {
	sum := sha256.Sum256([]byte(password))
	return hex.EncodeToString(sum[:])
}

// CheckPassword reports whether password matches the stored hash.
func CheckPassword(password, hash string) bool {
	return HashPassword(password) == hash
}