diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2022-06-04 20:14:16 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2022-06-04 20:14:16 -0700 |
| commit | d2810ae9038b057e8f18e8b495a57d8f96ae5be6 (patch) | |
| tree | f5cd374e2b2a782b1513f51cc7a72a5b8b8d0abc /hotline/account.go | |
| parent | d8e28ebc452ef2ebab2846451ce5589e028c5783 (diff) | |
Implement multi-account edit
Diffstat (limited to 'hotline/account.go')
| -rw-r--r-- | hotline/account.go | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/hotline/account.go b/hotline/account.go index 7368592..3da818f 100644 --- a/hotline/account.go +++ b/hotline/account.go @@ -1,7 +1,9 @@ package hotline import ( + "encoding/binary" "github.com/jhalter/mobius/concat" + "golang.org/x/crypto/bcrypt" ) const GuestAccount = "guest" // default account used when no login is provided for a connection @@ -15,10 +17,26 @@ type Account struct { // MarshalBinary marshals an Account to byte slice func (a *Account) MarshalBinary() (out []byte) { + fields := []Field{ + NewField(fieldUserName, []byte(a.Name)), + NewField(fieldUserLogin, negateString([]byte(a.Login))), + NewField(fieldUserAccess, *a.Access), + } + + if bcrypt.CompareHashAndPassword([]byte(a.Password), []byte("")) != nil { + fields = append(fields, NewField(fieldUserPassword, []byte("x"))) + } + + fieldCount := make([]byte, 2) + binary.BigEndian.PutUint16(fieldCount, uint16(len(fields))) + + var fieldPayload []byte + for _, field := range fields { + fieldPayload = append(fieldPayload, field.Payload()...) + } + return concat.Slices( - []byte{0x00, 0x3}, // param count -- always 3 - NewField(fieldUserName, []byte(a.Name)).Payload(), - NewField(fieldUserLogin, negateString([]byte(a.Login))).Payload(), - NewField(fieldUserAccess, *a.Access).Payload(), + fieldCount, + fieldPayload, ) } |