aboutsummaryrefslogtreecommitdiff
path: root/hotline/account.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2024-06-24 16:23:56 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2024-06-24 16:23:56 -0700
commita2ef262a164fc735b9b8471ac0c8001eea2b9bf6 (patch)
tree9a24fc5949df1183895a125e09cb262cdf79b073 /hotline/account.go
parenta55350daaf83498b7a237c027ad0dd2377f06fee (diff)
Refactoring, cleanup, test backfilling
Diffstat (limited to 'hotline/account.go')
-rw-r--r--hotline/account.go15
1 files changed, 10 insertions, 5 deletions
diff --git a/hotline/account.go b/hotline/account.go
index 18965ed..7b2aafe 100644
--- a/hotline/account.go
+++ b/hotline/account.go
@@ -5,7 +5,6 @@ import (
"fmt"
"golang.org/x/crypto/bcrypt"
"io"
- "log"
"slices"
)
@@ -20,6 +19,15 @@ type Account struct {
readOffset int // Internal offset to track read progress
}
+func NewAccount(login, name, password string, access accessBitmap) *Account {
+ return &Account{
+ Login: login,
+ Name: name,
+ Password: hashAndSalt([]byte(password)),
+ Access: access,
+ }
+}
+
// Read implements io.Reader interface for Account
func (a *Account) Read(p []byte) (int, error) {
fields := []Field{
@@ -57,10 +65,7 @@ func (a *Account) Read(p []byte) (int, error) {
// 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)
- }
+ hash, _ := bcrypt.GenerateFromPassword(pwd, bcrypt.MinCost)
return string(hash)
}