]> git.r.bdr.sh - rbdr/mobius/commitdiff
Minor cleanup
authorJeff Halter <redacted>
Sun, 3 Jul 2022 22:36:17 +0000 (15:36 -0700)
committerJeff Halter <redacted>
Sun, 3 Jul 2022 22:36:17 +0000 (15:36 -0700)
hotline/account.go
hotline/server.go
hotline/transaction_handlers.go
hotline/user.go

index a6808615f5fad507526b7b8b4ec3d59d52e0b9a6..9a0fb7dea55f56dcf0aace97223e0e32fac69650 100644 (file)
@@ -3,6 +3,7 @@ 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
 )
 
 const GuestAccount = "guest" // default account used when no login is provided for a connection
@@ -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)
+}
index 5b8aad0401f348a9d8fd118cb9a94e527f1af18c..852b7727b5da640d867b752cd69dfb1311d37a6c 100644 (file)
@@ -766,7 +766,6 @@ func (s *Server) handleFileTransfer(ctx context.Context, rwc io.ReadWriter) erro
        switch fileTransfer.Type {
        case bannerDownload:
                if err := s.bannerDownload(rwc); err != nil {
        switch fileTransfer.Type {
        case bannerDownload:
                if err := s.bannerDownload(rwc); err != nil {
-                       panic(err)
                        return err
                }
        case FileDownload:
                        return err
                }
        case FileDownload:
index 3ecb6bd046ab15f5a5c11bcaf317b2532f8fd781..afc24ff1b794e36dc344ca982d4f5a50ab1665fc 100644 (file)
@@ -462,7 +462,7 @@ func HandleSetFileInfo(cc *ClientConn, t *Transaction) (res []Transaction, err e
                                return res, err
                        }
                        if err != nil {
                                return res, err
                        }
                        if err != nil {
-                               panic(err)
+                               return res, err
                        }
                }
        }
                        }
                }
        }
index ff4006a188a6444b0bbbd7e12c1f6c727cba45d2..f6e4592ba9068a7e2b124e3943680681736d5b34 100644 (file)
@@ -2,8 +2,6 @@ package hotline
 
 import (
        "encoding/binary"
 
 import (
        "encoding/binary"
-       "golang.org/x/crypto/bcrypt"
-       "log"
 )
 
 // User flags are stored as a 2 byte bitmap with the following values:
 )
 
 // User flags are stored as a 2 byte bitmap with the following values:
@@ -77,18 +75,3 @@ func negateString(clearText []byte) []byte {
        }
        return obfuText
 }
        }
        return obfuText
 }
-
-func hashAndSalt(pwd []byte) string {
-       // Use GenerateFromPassword to hash & salt pwd.
-       // MinCost is just an integer constant provided by the bcrypt
-       // package along with DefaultCost & MaxCost.
-       // The cost can be any value you want provided it isn't lower
-       // than the MinCost (4)
-       hash, err := bcrypt.GenerateFromPassword(pwd, bcrypt.MinCost)
-       if err != nil {
-               log.Println(err)
-       }
-       // GenerateFromPassword returns a byte slice so we need to
-       // convert the bytes to a string and return it
-       return string(hash)
-}