mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-04-19 19:59:13 +03:00
CRC an actual dbuser struct
Per-field method left as a fallback
This commit is contained in:
parent
38e4f5cbec
commit
845f438087
1 changed files with 12 additions and 4 deletions
|
@ -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 {
|
||||
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(buf.Bytes())
|
||||
}
|
||||
|
||||
func ConcatMultipleSlices(slices ...[]byte) []byte {
|
||||
|
|
Loading…
Add table
Reference in a new issue