checks.go 976 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/nbutton23/zxcvbn-go"
  5. "strings"
  6. )
  7. // check each line of a diff and see if there are any potential
  8. // secrets
  9. func checkRegex(diff string) ([]string, bool) {
  10. var match string
  11. var results []string
  12. secretsPresent := false
  13. lines := strings.Split(diff, "\n")
  14. for _, line := range lines {
  15. if len(line) == 0 {
  16. continue
  17. }
  18. for _, re := range regexes {
  19. match = re.FindString(line)
  20. if len(match) == 0 {
  21. continue
  22. }
  23. secretsPresent = true
  24. results = append(results, line)
  25. }
  26. }
  27. return results, secretsPresent
  28. }
  29. // checkEntropy determines whether target contains enough
  30. // entropy for a hash
  31. func checkEntropy(target string) bool {
  32. index := assignRegex.FindStringIndex(target)
  33. if len(index) == 0 {
  34. return false
  35. }
  36. target = strings.Trim(target[index[1]:len(target)], " ")
  37. entropy := zxcvbn.PasswordStrength(target, nil).Entropy
  38. // tune this/make option
  39. if entropy > 70 {
  40. return true
  41. }
  42. return false
  43. }