Browse Source

BUGFIX: Fixed user creation triggering max password length error

master
parent
commit
a6a1556118
  1. 2
      pages/login.html
  2. 3
      pages/register.html
  3. 2
      src/server/endpoints.go
  4. 6
      src/server/validation.go

2
pages/login.html

@ -45,7 +45,7 @@ async function logIn() {
if (!emailInput.reportValidity()) {
return;
}
let email = String(emailInput.value).trim();
let email = String(emailInput.value).trim().toLowerCase();
let passwordInput = document.getElementById("input-password");
if (!passwordInput.reportValidity()) {

3
pages/register.html

@ -96,7 +96,7 @@ async function register() {
if (!emailInput.reportValidity()) {
return;
}
let email = String(emailInput.value).trim();
let email = String(emailInput.value).trim().toLowerCase();
let passwordInput = document.getElementById("input-password");
if (!passwordInput.reportValidity()) {
@ -111,6 +111,7 @@ async function register() {
password: passwordSHA256,
};
console.log(postData);
let response = await postNewUser(postData);
if (response.ok) {
let json = await response.json();

2
src/server/endpoints.go

@ -28,6 +28,7 @@ import (
"net/http"
"path"
"strconv"
"strings"
"time"
)
@ -62,6 +63,7 @@ func (s *Server) EndpointUserCreate(w http.ResponseWriter, req *http.Request) {
return
}
user.TimeCreatedUnix = uint64(time.Now().Unix())
user.Email = strings.ToLower(user.Email)
// Insert into DB
err = s.db.CreateUser(user)

6
src/server/validation.go

@ -32,7 +32,7 @@ const (
MinimalEmailLength uint = 3
MinimalPasswordLength uint = 5
MaxEmailLength uint = 50
MaxPasswordLength uint = 50
MaxPasswordLength uint = 100
MaxTodoTextLength uint = 250
MaxTodoFileSizeBytes uint = 3145728 // 3MB
)
@ -46,10 +46,10 @@ func IsUserValid(user db.User) (bool, string) {
return false, fmt.Sprintf("Email is too big; Email should be up to %d characters", MaxEmailLength)
}
if uint(len(user.Password)) < MinimalPasswordLength {
if uint(len([]rune(user.Password))) < MinimalPasswordLength {
return false, "Password is too small"
}
if uint(len(user.Password)) > MaxPasswordLength {
if uint(len([]rune(user.Password))) > MaxPasswordLength {
return false, fmt.Sprintf("Password is too big; Password should be up to %d characters", MaxPasswordLength)
}

Loading…
Cancel
Save