-
Notifications
You must be signed in to change notification settings - Fork 401
/
login.go
40 lines (34 loc) · 959 Bytes
/
login.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package post
import (
"net/smtp"
"github.com/zeebo/errs"
)
// LoginAuth implements LOGIN authentication mechanism.
type LoginAuth struct {
Username string
Password string
}
// Start begins an authentication with a server.
func (auth LoginAuth) Start(server *smtp.ServerInfo) (proto string, toServer []byte, err error) {
if !server.TLS {
return "", nil, errs.New("unencrypted connection")
}
return "LOGIN", nil, nil
}
// Next continues the authentication with server response and flag representing
// if server expects more data from client.
func (auth LoginAuth) Next(fromServer []byte, more bool) (toServer []byte, err error) {
if more {
switch string(fromServer) {
case "Username:":
return []byte(auth.Username), nil
case "Password:":
return []byte(auth.Password), nil
default:
return nil, errs.New("unknown question")
}
}
return nil, nil
}