SJA APS后端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.1 KiB

  1. package mysmtp
  2. import "errors"
  3. /*
  4. auth login
  5. */
  6. type loginAuth struct {
  7. username, password string
  8. host string
  9. }
  10. /*
  11. auth login 验证
  12. */
  13. func LoginAuth(username, password, host string) Auth {
  14. return &loginAuth{username, password, host}
  15. }
  16. /*
  17. 初步验证服务器信息输入账号
  18. */
  19. func (a *loginAuth) Start(server *ServerInfo) (string, []byte, error) {
  20. // 如果不是安全连接,也不是本地的服务器,报错,不允许不安全的连接
  21. if !server.TLS && !isLocalhost(server.Name) {
  22. return "", nil, errors.New("unencrypted connection")
  23. }
  24. // 如果服务器信息和 Auth 对象的服务器信息不一致,报错
  25. if server.Name != a.host {
  26. return "", nil, errors.New("wrong host name")
  27. }
  28. // 验证时需要的账号
  29. resp := []byte(a.username)
  30. // "auth login" 命令
  31. return "LOGIN", resp, nil
  32. }
  33. /*
  34. 进一步进行验证输入密码
  35. */
  36. func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
  37. // 如果服务器需要更多验证,报错
  38. if more {
  39. return []byte(a.password), nil
  40. }
  41. return nil, nil
  42. }