audit

package
v1.2.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckDuplicates added in v1.2.3

func CheckDuplicates(passwords map[string]string) (string, string, bool)

Types

type Audit

type Audit struct {
	// contains filtered or unexported fields
}

func New

func New(provider *Provider) *Audit

func (*Audit) Process

func (a *Audit) Process(in string) (bool, []string, error)

type Provider

type Provider struct {
	Name string
	//                 is secure, message
	//                     |        |
	//                     v		v
	Process func(string) (bool, []string, error)
}
var DefaultProvider *Provider = &Provider{
	Name: "default",
	Process: func(in string) (bool, []string, error) {

		var (
			secure  bool = true
			message []string

			symbols int
			digits  int
			upper   int
		)

		if len(in) < 32 {
			message = append(message, fmt.Sprintf("Password is too short (%d characters), should be at least 32", len(in)))
			secure = false
		}

		for _, c := range in {
			switch {
			case unicode.IsSymbol(c) || unicode.IsPunct(c):
				symbols++
			case unicode.IsDigit(c):
				digits++
			case unicode.IsUpper(c):
				upper++
			}
		}

		if symbols < 1 {
			message = append(message, "Password should contain at least one symbol")
			secure = false
		}

		if digits < 1 {
			message = append(message, "Password should contain at least one digit")
			secure = false
		}

		if upper < 1 {
			message = append(message, "Password should contain at least one upper case letter")
			secure = false
		}

		return secure, message, nil
	},
}
var HibpProvider *Provider = &Provider{
	Name: "hibp (haveibeenpwned.com)",
	Process: func(in string) (bool, []string, error) {
		check, err := hibp.Check(in)
		if err != nil {
			return false, nil, err
		}

		if check {
			return false, []string{"Password has been compromised"}, nil
		} else {
			return true, []string{""}, nil
		}
	},
}

func NewCustomProvider added in v1.2.3

func NewCustomProvider(min_length int, min_symbols int, min_digits int, min_upper int) *Provider

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL