Skip to content

Commit

Permalink
Merge 660f60a into 119d76d
Browse files Browse the repository at this point in the history
  • Loading branch information
cfclong committed Mar 17, 2021
2 parents 119d76d + 660f60a commit 2e6a3df
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/net/smtp/auth.go
Expand Up @@ -108,3 +108,31 @@ func (a *cramMD5Auth) Next(fromServer []byte, more bool) ([]byte, error) {
}
return nil, nil
}

//loginAuth
type loginAuth struct {
username, password string
host string
}

func LoginAuth(username, password, host string) Auth {
return &loginAuth{username, password, host}
}

func (a *loginAuth) Start(server *ServerInfo) (string, []byte, error) {
if !server.TLS && !isLocalhost(server.Name) {
return "", nil, errors.New("unencrypted connection")
}
if server.Name != a.host {
return "", nil, errors.New("wrong host name")
}
resp := []byte(a.username)
return "LOGIN", resp, nil
}

func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
if more {
return []byte(a.password), nil
}
return nil, nil
}

0 comments on commit 2e6a3df

Please sign in to comment.