aboutsummaryrefslogtreecommitdiff
path: root/tripcode.go
diff options
context:
space:
mode:
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"
}