5 "golang.org/x/crypto/bcrypt"
9 // User flags are stored as a 2 byte bitmap with the following values:
11 userFlagAway = 0 // User is away
12 userFlagAdmin = 1 // User is admin
13 userFlagRefusePM = 2 // User refuses private messages
14 userFLagRefusePChat = 3 // User refuses private chat
20 Flags []byte // Size 2
21 Name string // Variable length user name
24 func (u User) Payload() []byte {
25 nameLen := make([]byte, 2)
26 binary.BigEndian.PutUint16(nameLen, uint16(len(u.Name)))
32 if len(u.Flags) == 4 {
36 out := append(u.ID[:2], u.Icon[:2]...)
37 out = append(out, u.Flags[:2]...)
38 out = append(out, nameLen...)
39 out = append(out, u.Name...)
44 func ReadUser(b []byte) (*User, error) {
54 // DecodeUserString decodes an obfuscated user string from a client
55 // e.g. 98 8a 9a 8c 8b => "guest"
56 func DecodeUserString(obfuText []byte) (clearText string) {
57 for _, char := range obfuText {
58 clearText += string(rune(255 - uint(char)))
63 // negateString takes []byte s containing cleartext and rotates by 255 into obfuscated cleartext.
64 // The Hotline protocol uses this format for sending passwords over network.
65 // Not secure, but hey, it was the 90s!
66 func negateString(clearText []byte) []byte {
67 obfuText := make([]byte, len(clearText))
68 for i := 0; i < len(clearText); i++ {
69 obfuText[i] = 255 - clearText[i]
74 func hashAndSalt(pwd []byte) string {
75 // Use GenerateFromPassword to hash & salt pwd.
76 // MinCost is just an integer constant provided by the bcrypt
77 // package along with DefaultCost & MaxCost.
78 // The cost can be any value you want provided it isn't lower
79 // than the MinCost (4)
80 hash, err := bcrypt.GenerateFromPassword(pwd, bcrypt.MinCost)
84 // GenerateFromPassword returns a byte slice so we need to
85 // convert the bytes to a string and return it