package gpaste import "golang.org/x/crypto/bcrypt" type User struct { Username string `json:"username"` HashedPassword []byte `json:"hashed_password"` } type UserStore interface { Get(username string) (*User, error) Store(user *User) error Delete(username string) error } func (u *User) ValidatePassword(password string) error { return bcrypt.CompareHashAndPassword(u.HashedPassword, []byte(password)) } func (u *User) SetPassword(password string) error { hashed, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) if err != nil { return err } u.HashedPassword = hashed return nil }