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

Commits on Feb 28, 2024

  1. feat: [torrust#503] add more contrains for usernames

    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 committed Feb 28, 2024
    Configuration menu
    Copy the full SHA
    553208e View commit details
    Browse the repository at this point in the history