MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / hashAPIKey

Function hashAPIKey

database/api_key.go:23–29  ·  view source on GitHub ↗

hashAPIKey creates a bcrypt hash of the API key for secure storage. bcrypt includes salt and is resistant to brute-force attacks.

(key string)

Source from the content-addressed store, hash-verified

21// hashAPIKey creates a bcrypt hash of the API key for secure storage.
22// bcrypt includes salt and is resistant to brute-force attacks.
23func hashAPIKey(key string) (string, error) {
24 hash, err := bcrypt.GenerateFromPassword([]byte(key), bcrypt.DefaultCost)
25 if err != nil {
26 return "", err
27 }
28 return string(hash), nil
29}
30
31// verifyAPIKey compares a plaintext key with a bcrypt hash.
32func verifyAPIKey(hashedKey, plainKey string) bool {

Callers 2

CreateAPIKeyMethod · 0.85
TestGetAPIKey_SuccessFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestGetAPIKey_SuccessFunction · 0.68