Skip to content

Commit

Permalink
add regexp nickname validation to login page
Browse files Browse the repository at this point in the history
  • Loading branch information
krustowski committed Jul 16, 2024
1 parent 84c4ce7 commit 5c5e4e6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
#

APP_NAME=litter-go
APP_VERSION=0.35.15
APP_VERSION=0.35.16
GOLANG_VERSION=1.22
2 changes: 1 addition & 1 deletion api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"name": "MIT",
"url": "https://github.com/krustowski/litter-go/blob/master/LICENSE"
},
"version": "0.35.15"
"version": "0.35.16"
},
"host": "littr.eu",
"basePath": "/api/v1",
Expand Down
2 changes: 1 addition & 1 deletion pkg/backend/router.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @title litter-go
// @version 0.35.15
// @version 0.35.16
// @description nanoblogging platform as PWA built on go-app framework
// @termsOfService https://littr.eu/tos

Expand Down
12 changes: 12 additions & 0 deletions pkg/frontend/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/sha512"
"encoding/json"
"fmt"
"regexp"
"strings"

"go.savla.dev/littr/configs"
Expand Down Expand Up @@ -94,6 +95,17 @@ func (c *loginContent) onClick(ctx app.Context, e app.Event) {
return
}

// don't allow special chars and spaces in the nickname
if !regexp.MustCompile(`^[a-zA-Z0-9]+$`).MatchString(nickname) {
toastText = "nickname can contain only chars a-z, A-Z and numbers"

ctx.Dispatch(func(ctx app.Context) {
c.toastText = toastText
c.toastShow = (toastText != "")
})
return
}

//passHash := sha512.Sum512([]byte(passphrase + app.Getenv("APP_PEPPER")))
passHash := sha512.Sum512([]byte(passphrase + appPepper))

Expand Down

0 comments on commit 5c5e4e6

Please sign in to comment.