all repos — postern

@ 8bbd7a84fa063eaf76ebf26f4887c9c2644053bf

Modern mail management

clone
git clone https:///postern.git

internal/model/user.go (view raw)

 1package model
 2
 3import (
 4	"golang.org/x/crypto/bcrypt"
 5)
 6
 7type User struct {
 8	ID        int
 9	Name      string
10	Addresses []string
11	Password  string `json:"password,omitempty"`
12	password  []byte
13}
14
15func (u *User) SetPassword(pw []byte) {
16	u.password = pw
17}
18
19// VerifyPassword checks a plaintext password against the stored sha256 hash.
20func (u *User) VerifyPassword(password []byte) error {
21	return bcrypt.CompareHashAndPassword(u.password, password)
22}
23
24type SMTPAuth struct {
25	ID       int
26	Name     string
27	Password string `json:"password,omitempty"`
28	password []byte
29}
30
31func (u *SMTPAuth) SetPassword(pw []byte) {
32	u.password = pw
33}
34
35// VerifyPassword checks a plaintext password against the stored sha256 hash.
36func (u *SMTPAuth) VerifyPassword(password []byte) error {
37	return bcrypt.CompareHashAndPassword(u.password, password)
38}