aboutsummaryrefslogtreecommitdiff
path: root/tripcode.go
diff options
context:
space:
mode:
authorFChannel0 <77419041+FChannel0@users.noreply.github.com>2021-08-17 12:41:20 -0700
committerGitHub <noreply@github.com>2021-08-17 12:41:20 -0700
commit21917eb2ea72fe40d70c2c991e821aace5430c23 (patch)
tree4dd4122a8661231181ead7c00bdc92c3d498589f /tripcode.go
parent149f71db2d6e1b704ff2712393da5276a622d4dd (diff)
parentc8e0fb94bac60679ccebfcdec9cefb32674b2eec (diff)
Merge pull request #51 from KushBlazingJudah/development
go fmt and docker configuration
Diffstat (limited to 'tripcode.go')
-rw-r--r--tripcode.go51
1 files changed, 25 insertions, 26 deletions
diff --git a/tripcode.go b/tripcode.go
index 7e19cf0..b567bf0 100644
--- a/tripcode.go
+++ b/tripcode.go
@@ -1,15 +1,15 @@
package main
import (
- "golang.org/x/text/encoding/japanese"
- "golang.org/x/text/transform"
- "github.com/simia-tech/crypt"
- "strings"
"bytes"
- "regexp"
"database/sql"
_ "github.com/lib/pq"
- "net/http"
+ "github.com/simia-tech/crypt"
+ "golang.org/x/text/encoding/japanese"
+ "golang.org/x/text/transform"
+ "net/http"
+ "regexp"
+ "strings"
)
const SaltTable = "" +
@@ -22,7 +22,6 @@ const SaltTable = "" +
"................................" +
"................................"
-
func TripCode(pass string) string {
pass = TripCodeConvert(pass)
@@ -32,25 +31,25 @@ func TripCode(pass string) string {
s := []rune(pass + "H..")[1:3]
for i, r := range s {
- salt[i] = rune(SaltTable[r % 256])
+ salt[i] = rune(SaltTable[r%256])
}
- enc, err := crypt.Crypt(pass, "$1$" + string(salt[:]))
-
+ enc, err := crypt.Crypt(pass, "$1$"+string(salt[:]))
+
CheckError(err, "crypt broke")
-
- return enc[len(enc) - 10 : len(enc)]
+
+ return enc[len(enc)-10 : len(enc)]
}
func TripCodeSecure(pass string) string {
pass = TripCodeConvert(pass)
- enc, err := crypt.Crypt(pass, "$1$" + Salt)
-
+ enc, err := crypt.Crypt(pass, "$1$"+Salt)
+
CheckError(err, "crypt secure broke")
-
- return enc[len(enc) - 10 : len(enc)]
+
+ return enc[len(enc)-10 : len(enc)]
}
func TripCodeConvert(str string) string {
@@ -76,30 +75,30 @@ func CreateNameTripCode(r *http.Request, db *sql.DB) (string, string) {
if tripSecure.MatchString(input) {
chunck := tripSecure.FindString(input)
chunck = strings.Replace(chunck, "##", "", 1)
-
- ce := regexp.MustCompile(`(?i)Admin`)
+
+ ce := regexp.MustCompile(`(?i)Admin`)
admin := ce.MatchString(chunck)
board, modcred := GetPasswordFromSession(r)
-
- if(admin && HasAuth(db, modcred, board)) {
+
+ if admin && HasAuth(db, modcred, board) {
return tripSecure.ReplaceAllString(input, ""), "#Admin"
}
hash := TripCodeSecure(chunck)
return tripSecure.ReplaceAllString(input, ""), "!!" + hash
- }
-
+ }
+
trip := regexp.MustCompile("#(.+)?")
if trip.MatchString(input) {
chunck := trip.FindString(input)
chunck = strings.Replace(chunck, "#", "", 1)
-
- ce := regexp.MustCompile(`(?i)Admin`)
+
+ ce := regexp.MustCompile(`(?i)Admin`)
admin := ce.MatchString(chunck)
board, modcred := GetPasswordFromSession(r)
-
- if(admin && HasAuth(db, modcred, board)) {
+
+ if admin && HasAuth(db, modcred, board) {
return trip.ReplaceAllString(input, ""), "#Admin"
}