go: discord/modules: Do better hashing while obfuscating

Luther Wen Xu 2019-10-19 23:01:18 +07:00
parent 0bec62f96c
commit b6685d22bb
Signed by untrusted user: chanbakjsd
GPG Key ID: B7D77E3E9D102B70
1 changed files with 5 additions and 4 deletions

@ -63,7 +63,7 @@ var viewTrustLevel = adminOnly(func(s *discordgo.Session, m *discordgo.MessageCr
).Send(s, m.ChannelID) ).Send(s, m.ChannelID)
return return
} }
value, err := backend.GetTrust(s, command[1]) value, err := backend.GetTrust(s, user.User.ID)
if err != nil { if err != nil {
message.AuditError(s, m.ChannelID, err) message.AuditError(s, m.ChannelID, err)
return return
@ -97,6 +97,8 @@ var viewTrustLevel = adminOnly(func(s *discordgo.Session, m *discordgo.MessageCr
rand.Read(salt) rand.Read(salt)
//Generate message //Generate message
hash := sha512.New()
hash.Write(salt)
msg := message.NewEmbed().SetColour(config.VTLColour).SetTitle(config.VTLGlobalTitle) msg := message.NewEmbed().SetColour(config.VTLColour).SetTitle(config.VTLGlobalTitle)
for _, v := range members { for _, v := range members {
value, err := backend.GetTrust(s, v.User.ID) value, err := backend.GetTrust(s, v.User.ID)
@ -111,9 +113,8 @@ var viewTrustLevel = adminOnly(func(s *discordgo.Session, m *discordgo.MessageCr
if len(command) > 1 { if len(command) > 1 {
username = v.User.Username + "#" + v.User.Discriminator username = v.User.Username + "#" + v.User.Discriminator
} else { } else {
saltedUsername := []byte(v.User.Username + "#" + v.User.Discriminator) toSalt := []byte(v.User.Username + "#" + v.User.Discriminator)
saltedUsername = append(saltedUsername, salt...) username = hex.EncodeToString(hash.Sum(toSalt))[:64]
username = hex.EncodeToString(sha512.New().Sum(saltedUsername))[:64]
if username == "" { if username == "" {
username = "<cannot calculate hash>" username = "<cannot calculate hash>"
} }