all repos — postern @ main

Modern mail management

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  []byte
12}
13
14func (u *User) SetPassword(pw []byte) {
15	u.password = pw
16}
17
18// VerifyPassword checks a plaintext password against the stored sha256 hash.
19func (u *User) VerifyPassword(password []byte) error {
20	return bcrypt.CompareHashAndPassword(u.password, password)
21}
22
23type SMTPAuth struct {
24	ID       int
25	Name     string
26	password []byte
27}
28
29func (u *SMTPAuth) SetPassword(pw []byte) {
30	u.password = pw
31}
32
33// VerifyPassword checks a plaintext password against the stored sha256 hash.
34func (u *SMTPAuth) VerifyPassword(password []byte) error {
35	return bcrypt.CompareHashAndPassword(u.password, password)
36}