Skip to content

password sha1 encryption - only use hashed password in database #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions meta_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
"time"

"github.com/boltdb/bolt"

"crypto/sha1"
"encoding/hex"
)

// MetaStore implements a metadata storage. It stores user credentials and Meta information
Expand Down Expand Up @@ -316,7 +319,10 @@ func (s *MetaStore) AddUser(user, pass string) error {
return errNoBucket
}

err := bucket.Put([]byte(user), []byte(pass))
pass_sha1b := sha1.Sum([]byte(pass))
pass_sha1 := hex.EncodeToString(pass_sha1b[:])

err := bucket.Put([]byte(user), []byte(pass_sha1))
if err != nil {
return err
}
Expand Down Expand Up @@ -439,5 +445,8 @@ func (s *MetaStore) Authenticate(user, password string) (string, bool) {
return nil
})

return user, value != "" && value == password
pass_sha1b := sha1.Sum([]byte(password))
pass_sha1 := hex.EncodeToString(pass_sha1b[:])

return user, value != "" && value == pass_sha1
}