]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/account.go
patch: v0.10.5
[rbdr/mobius] / hotline / account.go
index 2c400aceafb56e28c6746f4f582d8347f69ddeab..9a0fb7dea55f56dcf0aace97223e0e32fac69650 100644 (file)
@@ -3,15 +3,16 @@ package hotline
 import (
        "encoding/binary"
        "golang.org/x/crypto/bcrypt"
 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 {
 )
 
 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
 }
 
 // Read implements io.Reader interface for Account
@@ -19,7 +20,7 @@ func (a *Account) Read(p []byte) (n int, err error) {
        fields := []Field{
                NewField(fieldUserName, []byte(a.Name)),
                NewField(fieldUserLogin, negateString([]byte(a.Login))),
        fields := []Field{
                NewField(fieldUserName, []byte(a.Name)),
                NewField(fieldUserLogin, negateString([]byte(a.Login))),
-               NewField(fieldUserAccess, *a.Access),
+               NewField(fieldUserAccess, a.Access[:]),
        }
 
        if bcrypt.CompareHashAndPassword([]byte(a.Password), []byte("")) != nil {
        }
 
        if bcrypt.CompareHashAndPassword([]byte(a.Password), []byte("")) != nil {
@@ -37,3 +38,13 @@ func (a *Account) Read(p []byte) (n int, err error) {
 
        return len(p), nil
 }
 
        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)
+}