Let's restrict valid usernames.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4471 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2023-09-22 22:41:47 +00:00
parent 51301fc49e
commit 74a3efe78d
2 changed files with 27 additions and 0 deletions

View File

@ -113,6 +113,11 @@ function getCookies(headers) {
return cookies;
}
function isNameValid(name) {
let c = name.charAt(0);
return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) && name.split().map(x => x >= ('a' && x <= 'z') || x >= ('A' && x <= 'Z') || x >= ('0' && x <= '9'));
}
function handler(request, response) {
let session = getCookies(request.headers).session;
if (request.uri == "/login") {
@ -138,6 +143,7 @@ function handler(request, response) {
account = account ? JSON.parse(account) : account;
if (formData.register == "1") {
if (!account &&
isNameValid(formData.name) &&
formData.password == formData.confirm) {
let users = new Set();
let users_original = gDatabase.get('users');