Skip to content

Commit

Permalink
feat: add username and password checker (#36)
Browse files Browse the repository at this point in the history
* feat: add username and password checker
  • Loading branch information
alqubo authored Jul 29, 2024
1 parent 1f3a579 commit 133cce0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/modules/api/v1/account/register.request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { RequestType } from "shared/types/main.ts";
import { RequestMethod } from "shared/enums/main.ts";
import { System } from "system/main.ts";
import * as bcrypt from "bcrypt";
import {PASSWORD_REGEX, USERNAME_MAX_LENGTH, USERNAME_MIN_LENGTH} from "shared/consts/main.ts";

export const registerRequest: RequestType = {
method: RequestMethod.POST,
Expand All @@ -17,7 +18,21 @@ export const registerRequest: RequestType = {
},
);

//verify captcha
if (username.length > USERNAME_MAX_LENGTH || username.length < USERNAME_MIN_LENGTH)
return Response.json(
{ status: 400 },
{
status: 400,
},
);

if (!password.test(PASSWORD_REGEX))
return Response.json(
{ status: 400 },
{
status: 400,
},
);

const accountId = crypto.randomUUID();

Expand Down
4 changes: 4 additions & 0 deletions src/shared/consts/account.consts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const USERNAME_MAX_LENGTH = 16
export const USERNAME_MIN_LENGTH = 3

export const PASSWORD_REGEX = /^(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*])[A-Za-z0-9!@#$%^&*]{8,}$/;
1 change: 1 addition & 0 deletions src/shared/consts/main.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./config.consts.ts";
export * from "./session.consts.ts";
export * from "./account.consts.ts";

0 comments on commit 133cce0

Please sign in to comment.