pwdbro

package module
v0.0.0-...-0fb34fd Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2020 License: MIT Imports: 2 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

pwdbro

A Golang password strength checker toolkit

How to get it?
$ go get -u "github.com/hesahesa/pwdbro"
What is this?

This is Golang toolkit to check the strength of a password string. By default it contains three checker mechanism, and can be extended based on your need!

Default checking mechanism

By default, this toolkit contains 3 password strength checking mechanism, those are:

  • nonempty : checks whether a password string contains one or more character (this serves as an example on how to extend the toolkit using your own checker)
  • pwnedpasswords : check whether a password string is included in the pwnedpasswords database. Basically it is what https://haveibeenpwned.com/Passwords is doing, but using their API
  • zxcvbn : check whether a password string is strong enough according to the Dropbox's zxcvbn algorithm. We also extend the dataset of the algorithm using Indonesian wordlist database! (please refer to the go.mod of this project for more information)
How to use?

Supposed that you have a password string that you want to check

pwd  := "password"

to check using the default pwdbro checking mechanism, use this:

pwdbro := pwdbro.NewDefaultPwdBro()

status, err := pwdbro.RunChecks(pwd)
// or aleternatively, use this to run the checks in parallel
status, err := pwdbro.RunParallelChecks(pwd)

you can then evaluate the result:

for _, resp := range status {
	// in practice, you will want to evaluate based on the
	// resp.Safe field and not just printing it
	
	fmt.Println(resp.Safe)
	fmt.Println(resp.Method)
	fmt.Println(resp.Message)
	fmt.Println(resp.Error)
}
Implementing your own checker

To implement your own checking mechanism, you need to create a struct that implements pwdbro.PwdChecker interface, for example:

type MyChecker struct {
}

// MethodName returns the method name of this checker
func (m *MyChecker) MethodName() string {
	return "My Checker Method Name"
}

// CheckPassword returns true if the supplied string is "safe" to use as password
func (m *MyChecker) CheckPassword(pwd string) (bool, string, error) {
	// implements your password checking logic in here
}

and then you can add it to an existing pwdbro instance

pwdbro := pwdbro.NewDefaultPwdBro()
// or if you want a pwdbro with no default checkers
pwdbro := pwdbro.NewEmptyPwdBro()

// add your custom checker
pwdbro.AddChecker(&MyChecker{})

// run the checks
status, err := pwdbro.RunChecks(pwd)
Made with <3 by @hesahesa

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PwdBro

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

PwdBro is a struct to hold pwdbro instance

func NewDefaultPwdBro

func NewDefaultPwdBro() *PwdBro

NewDefaultPwdBro return an instance of PwdBro with default checking mechanisms

func NewEmptyPwdBro

func NewEmptyPwdBro() *PwdBro

NewEmptyPwdBro return an instance of PwdBro without no checking mechanism you could add your desired checker by using AddChecker() method

func (*PwdBro) AddChecker

func (pwdb *PwdBro) AddChecker(c PwdChecker) error

AddChecker add a PwdChecker to the list of method of pwdbro

func (*PwdBro) RunChecks

func (pwdb *PwdBro) RunChecks(pwd string) ([]*PwdStatus, error)

RunChecks run all checks for a password string

func (*PwdBro) RunParallelChecks

func (pwdb *PwdBro) RunParallelChecks(pwd string) ([]*PwdStatus, error)

RunParallelChecks run all checks for a password string in parallel

type PwdChecker

type PwdChecker interface {
	// The method name used, it should return a string denoting the method identifier
	MethodName() string
	// The method that is called when checking password, it accept a password string
	// and should return a boolean denoting whether the password is safe/not, a string
	// denoting additional message, and an error denoting if there is any error when
	// running the method
	CheckPassword(string) (bool, string, error)
}

PwdChecker is an interface to check password strength

type PwdStatus

type PwdStatus struct {
	Method  string
	Safe    bool
	Message string
	Error   error
}

PwdStatus is a struct to hold password status after check

func NewPwdStatus

func NewPwdStatus(safe bool, message string, err error) *PwdStatus

NewPwdStatus construct a new PwdStatus struct

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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