wagslane / go-password-validator

Validate the Strength of a Password in Go
https://blog.boot.dev/open-source/how-to-validate-passwords/
MIT License
500 stars 40 forks source link

passwordvalidator.Validate always return nil error, even when the supplied password is well below min entropy #10

Closed satish71 closed 3 years ago

satish71 commented 3 years ago

Describe the bug Validate method always returns nil error, even when password entropy is less than minimum entropy

To Reproduce No additional steps required, it is a main line usecase. try with password as "123" with minimum entropy as 60 func strongPass(password string) error { const minEntropyBits = 60 err := passwordvalidator.Validate(password, minEntropyBits) return err }

The problem is the following code, when you return error object it is nil to calling function, as the call fmt.Errorf it is by value and is lost on return.

if len(allMessages) > 0 {
    return fmt.Errorf(
        "insecure password, try %v or using a longer password",
        strings.Join(allMessages, ", "),
    )
}

Expected behavior Should return an error.

Screenshots None

Environment (please complete the following information):

Additional context None

wagslane commented 3 years ago

Sorry, I think your example is mistaken. I just added the example you gave as a unit test and it performs as expected. Could you take another look or provide a different example pelase.