more logging
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-01-09 21:30:14 +11:00
parent d86ce64ea7
commit b4355ee913

View File

@@ -46,14 +46,17 @@ func storeKeyHash(plaintext string, filePath string) error {
func compareHashWithPlaintext(plaintext string, filePath string) (bool, error) { func compareHashWithPlaintext(plaintext string, filePath string) (bool, error) {
hashBytes, err := os.ReadFile(filePath) hashBytes, err := os.ReadFile(filePath)
if err != nil { if err != nil {
log.Printf("compareHashWithPlaintext error reading hashfile : '%s'\n", err)
return false, err return false, err
} }
err = bcrypt.CompareHashAndPassword(hashBytes, []byte(plaintext)) err = bcrypt.CompareHashAndPassword(hashBytes, []byte(plaintext))
if err != nil { if err != nil {
if err == bcrypt.ErrMismatchedHashAndPassword { if err == bcrypt.ErrMismatchedHashAndPassword {
log.Printf("compareHashWithPlaintext provided key is incorrect")
return false, nil // Passwords don't match return false, nil // Passwords don't match
} }
log.Printf("compareHashWithPlaintext error comparing provided key : '%s'\n", err)
return false, err // Other error occurred return false, err // Other error occurred
} }
@@ -71,6 +74,7 @@ func ReceiveKey(key string) error {
filePath, _ := getHashFilePath() filePath, _ := getHashFilePath()
if filePath != "" { if filePath != "" {
log.Printf("ReceiveKey detected hash file at '%s'\n", filePath)
// File already exists, compare received key with hash in file // File already exists, compare received key with hash in file
compare, err := compareHashWithPlaintext(key, filePath) compare, err := compareHashWithPlaintext(key, filePath)
if err != nil { if err != nil {