X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/926c7f5505456a0900e9c49f6c08efebe9a53505..e55ecb6c4a75d1d16b6785dbe9f75f9e22291a21:/hotline/account.go diff --git a/hotline/account.go b/hotline/account.go index 2c400ac..c51162d 100644 --- a/hotline/account.go +++ b/hotline/account.go @@ -3,27 +3,28 @@ package hotline import ( "encoding/binary" "golang.org/x/crypto/bcrypt" + "log" ) const GuestAccount = "guest" // default account used when no login is provided for a connection type Account struct { - Login string `yaml:"Login"` - Name string `yaml:"Name"` - Password string `yaml:"Password"` - Access *[]byte `yaml:"Access"` // 8 byte bitmap + Login string `yaml:"Login"` + Name string `yaml:"Name"` + Password string `yaml:"Password"` + Access accessBitmap `yaml:"Access"` } // Read implements io.Reader interface for Account func (a *Account) Read(p []byte) (n int, err error) { fields := []Field{ - NewField(fieldUserName, []byte(a.Name)), - NewField(fieldUserLogin, negateString([]byte(a.Login))), - NewField(fieldUserAccess, *a.Access), + 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"))) + fields = append(fields, NewField(FieldUserPassword, []byte("x"))) } fieldCount := make([]byte, 2) @@ -37,3 +38,13 @@ func (a *Account) Read(p []byte) (n int, err error) { return len(p), nil } + +// hashAndSalt generates a password hash from a users obfuscated plaintext password +func hashAndSalt(pwd []byte) string { + hash, err := bcrypt.GenerateFromPassword(pwd, bcrypt.MinCost) + if err != nil { + log.Println(err) + } + + return string(hash) +}