passwd
import "toolman.org/security/tools/passwd"
Package passwd provides tools and utilities for entering, checking and
changing passwords on the command line (without echoing back to the
terminal)
go get toolman.org/security/tools/passwd
session.go
var Prompts = &PromptSet{
Get: "Password: ",
Old: "Old Password: ",
New1: "New Password: ",
New2: "New Password (again): ",
}
Prompts provides a reasonable set of default prompt values.
func Compare(pass, hash []byte) error
Compare is used to compare the provided plain-text password and bcrypt hash
value. It is equivlent to bcrypt.CompareHashAndPassword(hash, pass)
type PromptSet struct {
Get string
Old string
New1 string
New2 string
}
A PromptSet is a set of strings used for prompting the user to enter
a password. Each field is used in a different situation.
func (p *PromptSet) Change(oldHash []byte) ([]byte, error)
Change is a convenience wrapper around Check and NewHash for changing an
exising passsword. If the user's current password is provided as oldHash,
the user is prompted for their current password (using the Old prompt). If
and only if the entered password matches the priveded hash is the user then
prompted to enter a new password similar to NewPass. If successful, the
bcrypt has of the newly entered password is returned -- or, if not, an
appropriate error is emitted.
func (p *PromptSet) Check(hash []byte) error
Check prompts the user for a password similar to GetPass then compares the
entered password to the provided bcrypt hash value. If they agree, nill is
returned -- otherwise an approprate error is returned.
func (p *PromptSet) GetHash() ([]byte, error)
GetHash is a wrapper around GetPass that returns a bcrypt hash of the
entered password.
func (p *PromptSet) GetPass() ([]byte, error)
GetPass prompts the user to enter a password (using the Get prompt), reads
the password string from stdin without echoing back to the terminal, and
returns the plain text password as a byte array -- or, returns nil and en
error if a problem occurred.
func (p *PromptSet) NewHash() ([]byte, error)
NewHash is a wrapper around NewPass that returns a bcrypt hash of the
entered password.
func (p *PromptSet) NewPass() ([]byte, error)
NewPass prompts the user to enter a new password two separate times -- first
using the New1 prompt then with the New2 prompt, Each time it reads the
password string from stdin without echoing back to the terminal. If the two
password strings agree, the plain text password is returned as a byte array.
If they do not, the user is informed as such and the cycle is restarted --
unless the user presses Enter for both prompts (which aborts the process).
Up to 4 attempts are made to acquire a new password. If the user aborts the
process, exhausts all attempts or some other error occurs, a nil array and
an error is returned instead.
error if a problem occurred.
Generated by godoc2md