package model import ( "golang.org/x/crypto/bcrypt" ) type User struct { ID int Name string Addresses []string password []byte } func (u *User) SetPassword(pw []byte) { u.password = pw } // VerifyPassword checks a plaintext password against the stored sha256 hash. func (u *User) VerifyPassword(password []byte) error { return bcrypt.CompareHashAndPassword(u.password, password) } type SMTPAuth struct { ID int Name string password []byte } func (u *SMTPAuth) SetPassword(pw []byte) { u.password = pw } // VerifyPassword checks a plaintext password against the stored sha256 hash. func (u *SMTPAuth) VerifyPassword(password []byte) error { return bcrypt.CompareHashAndPassword(u.password, password) }