diff --git a/util/util.go b/util/util.go index d9b9bc0..e294639 100644 --- a/util/util.go +++ b/util/util.go @@ -2,6 +2,8 @@ package util import ( "bufio" + "bytes" + "encoding/gob" "encoding/json" "errors" "fmt" @@ -830,11 +832,17 @@ func filterStringSlice(s []string, excludedStr string) []string { } func GetDBUserCRC32(dbuser model.User) uint32 { - var isAdmin byte = 0 - if dbuser.Admin { - isAdmin = 1 + buf := new(bytes.Buffer) + enc := gob.NewEncoder(buf) + if err := enc.Encode(dbuser); err != nil { + // Should be unreachable, fallback for the case + var isAdmin byte = 0 + if dbuser.Admin { + isAdmin = 1 + } + return crc32.ChecksumIEEE(ConcatMultipleSlices([]byte(dbuser.Username), []byte{isAdmin}, []byte(dbuser.PasswordHash), []byte(dbuser.Password))) } - return crc32.ChecksumIEEE(ConcatMultipleSlices([]byte(dbuser.Username), []byte{isAdmin}, []byte(dbuser.PasswordHash), []byte(dbuser.Password))) + return crc32.ChecksumIEEE(buf.Bytes()) } func ConcatMultipleSlices(slices ...[]byte) []byte {