aboutsummaryrefslogtreecommitdiff
path: root/tripcode.go
diff options
context:
space:
mode:
authorKushBlazingJudah <59340248+KushBlazingJudah@users.noreply.github.com>2021-11-10 15:45:27 -0400
committerFChannel <>2022-06-19 12:53:29 -0700
commitf1f2044c2f2bc24ea2a08c58b4517e1e07f4039c (patch)
treefbc684b8f4a13145bfaebd71ee6f224cea169eef /tripcode.go
parente15bf8cd1375f24251929ff3e13f883f692ee03a (diff)
it compiles now
Diffstat (limited to 'tripcode.go')
-rw-r--r--tripcode.go67
1 files changed, 36 insertions, 31 deletions
diff --git a/tripcode.go b/tripcode.go
index 9947db6..44651bb 100644
--- a/tripcode.go
+++ b/tripcode.go
@@ -2,11 +2,11 @@ package main
import (
"bytes"
- "database/sql"
"net/http"
"regexp"
"strings"
+ "github.com/FChannel0/FChannel-Server/config"
_ "github.com/lib/pq"
"github.com/simia-tech/crypt"
"golang.org/x/text/encoding/japanese"
@@ -23,8 +23,7 @@ const SaltTable = "" +
"................................" +
"................................"
-func TripCode(pass string) string {
-
+func TripCode(pass string) (string, error) {
pass = TripCodeConvert(pass)
var salt [2]rune
@@ -36,26 +35,28 @@ func TripCode(pass string) string {
}
enc, err := crypt.Crypt(pass, "$1$"+string(salt[:]))
+ if err != nil {
+ return "", err
+ }
- CheckError(err, "crypt broke")
-
- return enc[len(enc)-10 : len(enc)]
+ // normally i would just return error here but if the encrypt fails, this operation may fail and as a result cause a panic
+ return enc[len(enc)-10 : len(enc)], nil
}
-func TripCodeSecure(pass string) string {
-
+func TripCodeSecure(pass string) (string, error) {
pass = TripCodeConvert(pass)
- enc, err := crypt.Crypt(pass, "$1$"+Salt)
-
- CheckError(err, "crypt secure broke")
+ enc, err := crypt.Crypt(pass, "$1$"+config.Salt)
+ if err != nil {
+ return "", err
+ }
- return enc[len(enc)-10 : len(enc)]
+ return enc[len(enc)-10 : len(enc)], nil
}
func TripCodeConvert(str string) string {
-
var s bytes.Buffer
+
transform.NewWriter(&s, japanese.ShiftJIS.NewEncoder()).Write([]byte(str))
re := strings.NewReplacer(
@@ -68,7 +69,10 @@ func TripCodeConvert(str string) string {
return re.Replace(s.String())
}
-func CreateNameTripCode(r *http.Request, db *sql.DB) (string, string) {
+func CreateNameTripCode(r *http.Request) (string, string, error) {
+ // TODO: to allow this to compile, this will fail for the case of the admin
+ // this can be easily fixed when the rest of the code gets converted to fiber
+
input := r.FormValue("name")
tripSecure := regexp.MustCompile("##(.+)?")
@@ -77,16 +81,17 @@ func CreateNameTripCode(r *http.Request, db *sql.DB) (string, string) {
chunck := tripSecure.FindString(input)
chunck = strings.Replace(chunck, "##", "", 1)
- ce := regexp.MustCompile(`(?i)Admin`)
- admin := ce.MatchString(chunck)
- board, modcred := GetPasswordFromSession(r)
+ //ce := regexp.MustCompile(`(?i)Admin`)
+ //admin := ce.MatchString(chunck)
+
+ //board, modcred := GetPasswordFromSession(r)
- if admin && HasAuth(db, modcred, board) {
- return tripSecure.ReplaceAllString(input, ""), "#Admin"
- }
+ //if admin && HasAuth(modcred, board) {
+ // return tripSecure.ReplaceAllString(input, ""), "#Admin"
+ //}
- hash := TripCodeSecure(chunck)
- return tripSecure.ReplaceAllString(input, ""), "!!" + hash
+ hash, err := TripCodeSecure(chunck)
+ return tripSecure.ReplaceAllString(input, ""), "!!" + hash, err
}
trip := regexp.MustCompile("#(.+)?")
@@ -95,17 +100,17 @@ func CreateNameTripCode(r *http.Request, db *sql.DB) (string, string) {
chunck := trip.FindString(input)
chunck = strings.Replace(chunck, "#", "", 1)
- ce := regexp.MustCompile(`(?i)Admin`)
- admin := ce.MatchString(chunck)
- board, modcred := GetPasswordFromSession(r)
+ //ce := regexp.MustCompile(`(?i)Admin`)
+ //admin := ce.MatchString(chunck)
+ //board, modcred := GetPasswordFromSession(r)
- if admin && HasAuth(db, modcred, board) {
- return trip.ReplaceAllString(input, ""), "#Admin"
- }
+ //if admin && HasAuth(db, modcred, board) {
+ // return trip.ReplaceAllString(input, ""), "#Admin"
+ //}
- hash := TripCode(chunck)
- return trip.ReplaceAllString(input, ""), "!" + hash
+ hash, err := TripCode(chunck)
+ return trip.ReplaceAllString(input, ""), "!" + hash, err
}
- return input, ""
+ return input, "", nil
}