Skip to content

Commit

Permalink
Fix support raw username/password for tapo source #748
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Nov 14, 2023
1 parent aa3c081 commit 54b1999
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions pkg/tapo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ func (c *Client) newConn() (net.Conn, error) {
return nil, err
}

// support raw username/password or cloud password in place of username
if _, ok := u.User.Password(); !ok {
u.User = url.UserPassword("admin", u.User.Username())
}

if u.Port() == "" {
u.Host += ":8800"
}
Expand Down Expand Up @@ -269,10 +264,14 @@ func dial(req *http.Request) (net.Conn, *http.Response, error) {
return nil, nil, err
}

if strings.Contains(auth, `encrypt_type="3"`) {
password = fmt.Sprintf("%32X", sha256.Sum256([]byte(password)))
} else {
password = fmt.Sprintf("%16X", md5.Sum([]byte(password)))
if password == "" {
// support cloud password in place of username
if strings.Contains(auth, `encrypt_type="3"`) {
password = fmt.Sprintf("%32X", sha256.Sum256([]byte(username)))
} else {
password = fmt.Sprintf("%16X", md5.Sum([]byte(username)))
}
username = "admin"
}

realm := tcp.Between(auth, `realm="`, `"`)
Expand Down

0 comments on commit 54b1999

Please sign in to comment.