Password validator library for Go alternatives and similar packages
Based on the "Validation" category.
Alternatively, view Password validator library for Go alternatives based on common mentions on social networks and blogs.
-
validator
:100:Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving -
govalidator
[Go] Package of validators and sanitizers for strings, numerics, slices and structs -
ozzo-validation
An idiomatic Go (golang) validation package. Supports configurable and extensible validation rules (validators) using normal language constructs instead of error-prone struct tags. -
Validate
⚔ Go package for data validation and filtering. support Map, Struct, Form data. Go通用的数据验证与过滤库,使用简单,内置大部分常用验证、过滤器,支持自定义验证器、自定义消息、字段翻译。 -
Handy Go utilities
GO Golang Utilities and helpers like validators and string formatters -
checkdigit
Provide check digit algorithms and calculators written in Go -
terraform-validator
A norms and conventions validator for Terraform -
gody
:balloon: A lightweight struct validator for Go -
simpex
A simpler and faster alternative to regexp -
postcode
Small Golang package for validating postal codes -
Errdetail
Wrap multiple errors in one Go error type.
Access the most powerful time series database as a service
Do you think we are missing an alternative of Password validator library for Go or a related project?
README
Password validator library for Go
Installation
go get -u github.com/go-passwd/validator
Usage
import "github.com/go-passwd/validator"
passwordValidator := validator.New(validator.MinLength(5, nil), validator.MaxLength(10, nil))
err := passwordValidator.Validate(form.Password)
if err != nil {
panic(err)
}
You can pass to every validator functions customError
parameter witch will be returned on error instead of default error.
import "github.com/go-passwd/validator"
passwordValidator := validator.New(validator.MinLength(5, errors.New("too short")), validator.MaxLength(10, errors.New("too long")))
err := passwordValidator.Validate(form.Password)
if err != nil {
panic(err)
}
Validators
CommonPassword
Check if password is a common password.
Common password list is based on list created by Mark Burnett: https://xato.net/passwords/more-top-worst-passwords/
passwordValidator := validator.New(validator.CommonPassword(nil))
ContainsAtLeast
Count occurrences of a chars and compares it with required value.
passwordValidator := validator.New(validator.ContainsAtLeast(5, "abcdefghijklmnopqrstuvwxyz", nil))
ContainsOnly
Check if password contains only selected chars.
passwordValidator := validator.New(validator.ContainsOnly("abcdefghijklmnopqrstuvwxyz", nil))
MaxLength
Check if password length is not greater that defined length.
passwordValidator := validator.New(validator.MaxLength(10, nil))
MinLength
Check if password length is not lower that defined length.
passwordValidator := validator.New(validator.MinLength(5, nil))
Noop
Always return custom error.
passwordValidator := validator.New(validator.Noop(nil))
Regex
Check if password match regexp pattern.
passwordValidator := validator.New(validator.Regex("^\\w+$", nil))
Similarity
Check if password is sufficiently different from the attributes.
Attributes can be: user login, email, first name, last name, …
passwordValidator := validator.New(validator.Similarity([]string{"username", "[email protected]"}, nil, nil))
StartsWith
Check if password starts with one of letter.
passwordValidator := validator.New(validator.StartsWith("abcdefghijklmnopqrstuvwxyz", nil))
Unique
Check if password contains only unique chars.
passwordValidator := validator.New(validator.Unique(nil))