5 "golang.org/x/crypto/bcrypt"
11 const GuestAccount = "guest" // default account used when no login is provided for a connection
14 Login string `yaml:"Login"`
15 Name string `yaml:"Name"`
16 Password string `yaml:"Password"`
17 Access accessBitmap `yaml:"Access"`
20 // Read implements io.Reader interface for Account
21 func (a *Account) Read(p []byte) (n int, err error) {
23 NewField(FieldUserName, []byte(a.Name)),
24 NewField(FieldUserLogin, encodeString([]byte(a.Login))),
25 NewField(FieldUserAccess, a.Access[:]),
28 if bcrypt.CompareHashAndPassword([]byte(a.Password), []byte("")) != nil {
29 fields = append(fields, NewField(FieldUserPassword, []byte("x")))
32 fieldCount := make([]byte, 2)
33 binary.BigEndian.PutUint16(fieldCount, uint16(len(fields)))
36 for _, field := range fields {
37 fieldBytes = append(fieldBytes, field.Payload()...)
40 return copy(p, slices.Concat(fieldCount, fieldBytes)), io.EOF
43 // hashAndSalt generates a password hash from a users obfuscated plaintext password
44 func hashAndSalt(pwd []byte) string {
45 hash, err := bcrypt.GenerateFromPassword(pwd, bcrypt.MinCost)