US
usvc/go-password
A Go package to manage password hashing, verification, and validation
Password
A Go package to manage password hashing, verification, and validation.
| Github | https://github.com/usvc/go-password |
| Gitlab | https://gitlab.com/usvc/modules/go/password |
Usage
Importing
import "github.com/usvc/go-password"Hashing Passwords
plaintext := "abcd1234!@#$"
hash, salt, err := password.Hash(plaintext, 32)
// ...
// store the hash and salt
// ...Verifying Passwords
storedHash := "<hash>"
storedSalt := "<salt>"
plaintext := "abcd1234!@#$"
err := password.Verify(plaintext, storedHash, storedSalt)
if err != nil {
// handle failed verification
} else {
// handle successful verification
}Validating Passwords
defaultPolicy := password.GetDefaultPolicy()
plaintext := "abcd1234!@#$"
if err := password.Validate(plaintext, defaultPolicy); err != nil {
// handle failed validation
} else {
// handle successful validation
}Customizing Password Policies
customPolicy := password.Policy{
MaximumLength: 32,
MinimumLength: 12,
MinimumLowercaseCount: 1,
MinimumUppercaseCount: 1,
MinimumNumericCount: 1,
MinimumSpecialCount: 1,
CustomSpecial: []byte("`!@"),
}
plaintext := "abcd1234!@#$"
if err := password.Validate(plaintext, defaultPolicy); err != nil {
// handle failed validation
} else {
// handle successful validation
}Development Runbook
Getting Started
- Clone this repository
- Run
make depsto pull in external dependencies - Write some awesome stuff
- Run
make testto ensure unit tests are passing - Push
Continuous Integration (CI) Pipeline
On Github
Github is used to deploy binaries/libraries because of it's ease of access by other developers.
Releasing
Releasing of the binaries can be done via Travis CI.
- On Github, navigate to the tokens settings page (by clicking on your profile picture, selecting Settings, selecting Developer settings on the left navigation menu, then Personal Access Tokens again on the left navigation menu)
- Click on Generate new token, give the token an appropriate name and check the checkbox on
public_repowithin the repo header - Copy the generated token
- Navigate to travis-ci.org and access the cooresponding repository there. Click on the More options button on the top right of the repository page and select Settings
- Scroll down to the section on Environment Variables and enter in a new NAME with
RELEASE_TOKENand the VALUE field cooresponding to the generated personal access token, and hit Add
On Gitlab
Version Bumping
To set up the CI pipeline in Gitlab:
- Run
make .ssh - Copy the contents of the file generated at
./.ssh/id_rsa.base64into an environment variable namedDEPLOY_KEYin Settings > CI/CD > Variables - Navigate to the Deploy Keys section of the Settings > Repository > Deploy Keys and paste in the contents of the file generated at
./.ssh/id_rsa.pubwith the Write access allowed checkbox enabled
DEPLOY_KEY: generate this by runningmake .sshand copying the contents of the file generated at./.ssh/id_rsa.base64
Licensing
Code in this package is licensed under the MIT license (click to view text).
On this page
Contributors
MIT License
Created February 19, 2020
Updated August 12, 2024