Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more contrains for usernames #504

Merged

Conversation

josecelano
Copy link
Member

Usernames will only allow the following characters:

  • Uppercase and lowercase letters (A-Z, a-z)
  • Digits (0-9)
  • The simple dash (-)
  • The underscore (_)

Additionally, we'll enforce a maximum length of 20 characters for the usernames.

We exclude emojis, blank spaces, non-valid UTF-8 characters, and non-ASCII characters

^[A-Za-z0-9-_]{1,20}$

Explanation:

  • ^ asserts the start of the string.
  • [A-Za-z0-9-] is a character class that matches uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and the simple dash (-) or underscore (_).
  • {1,20} quantifier makes sure that the preceding character class matches between 1 and 20 times, inclusive, which enforces your maximum length requirement.
  • $ asserts the end of the string.

This regular expression ensures that usernames consist only of the specified characters and do not exceed 20 characters in length. It effectively excludes emojis, blank spaces, non-valid UTF-8 characters, and non-ASCII characters, as they are not included in the specified character set.

The API endpoint /register for registration should return a Bad Request when the username does to match this regexp.

@josecelano josecelano self-assigned this Feb 28, 2024
@josecelano josecelano added Enhancement / Feature Request Something New - User - Enjoyable to Use our Software labels Feb 28, 2024
@josecelano josecelano added this to the v3.0.0 milestone Feb 28, 2024
@josecelano josecelano linked an issue Feb 28, 2024 that may be closed by this pull request
Usernames will only allow the following characters:

- Uppercase and lowercase letters (`A-Z`, `a-z`)
- Digits (`0-9`)
- The simple dash (`-`)
- The underscore (`_`)

Additionally, we'll enforce a maximum length of 20 characters for the usernames.

We exclude emojis, blank spaces, non-valid UTF-8 characters, and non-ASCII characters

```regex
^[A-Za-z0-9-_]{1,20}$
```

Explanation:

- `^` asserts the start of the string.
- `[A-Za-z0-9-]` is a character class that matches uppercase letters (`A-Z`), lowercase letters (`a-z`), digits (`0-9`), and the simple dash (`-`) or underscore (`_`).
- `{1,20}` quantifier makes sure that the preceding character class matches between 1 and 20 times, inclusive, which enforces your maximum length requirement.
- `$` asserts the end of the string.

This regular expression ensures that usernames consist only of the specified characters and do not exceed 20 characters in length. It effectively excludes emojis, blank spaces, non-valid UTF-8 characters, and non-ASCII characters, as they are not included in the specified character set.

The API endpoint `/register` for registration should return a Bad Request when the username does to match this regexp.
@josecelano
Copy link
Member Author

ACK 553208e

@josecelano josecelano merged commit eb87363 into torrust:develop Feb 28, 2024
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- User - Enjoyable to Use our Software Enhancement / Feature Request Something New
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validate username before signup
1 participant