Documentation ¶
Overview ¶
Example ¶
Example of upgrading password hash to a greater complexity.
Note: This example uses very unsecure hash functions to allow for predictable output. Use of argon2.Argon2id or scrypt.Scrypt2 for greater hash security is recommended.
package main import ( "fmt" "go.sour.is/passwd" "go.sour.is/passwd/pkg/argon2" "go.sour.is/passwd/pkg/unix" ) func main() { pass := []byte("my_pass") hash := []byte("$1$81ed91e1131a3a5a50d8a68e8ef85fa0") pwd := passwd.New( argon2.Argon2id, // first is preferred type. &unix.MD5{}, ) _, err := pwd.Passwd(pass, hash) if err != nil { fmt.Println("fail: ", err) return } // Check if we want to update. if !pwd.IsPreferred(hash) { newHash, err := pwd.Passwd(pass, nil) if err != nil { fmt.Println("fail: ", err) return } fmt.Println("new hash:", string(newHash)[:31], "...") } }
Output: new hash: $argon2id$v=19,m=65536,t=1,p=4$ ...
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrBadHash = errors.New("password hash is malformed")
View Source
var ErrNoHandler = errors.New("password handler not registered")
View Source
var ErrNoMatch = errors.New("password does not match")
Functions ¶
This section is empty.
Types ¶
type Passwd ¶
type Passwd struct {
// contains filtered or unexported fields
}
func (*Passwd) IsPreferred ¶
func (*Passwd) SetDefault ¶
func (*Passwd) SetFallthrough ¶
Click to show internal directories.
Click to hide internal directories.