Skip to content

Conversation

@Manancode
Copy link

Changes Made:
Introduced a generateUsername function:
This function takes an email address, splits it into the local part and the domain part, and creates a unique username by appending a hashed version of the domain to the local part.
The hashing uses the SHA-256 algorithm and takes the first 8 characters of the hash to keep it concise.
Updated the registration controller:
Integrated the new generateUsername function to generate unique usernames before sending the registration request.

Why These Changes Were Made:
Problem: Previously, usernames were generated using only the local part of the email (e.g., [email protected] would generate xyz as the username). This led to conflicts when multiple users had the same local part but different domains (e.g., [email protected] and [email protected]).
Solution: By incorporating the domain part into the username (through hashing), we ensure that usernames are unique even if the local parts of the emails are the same but the domains are different.

Example:
Email: [email protected] -> Username: xyz_937d4a34
Email: [email protected] -> Username: xyz_85e5324f
Email: [email protected] -> Username: abc_937d4a34

(USING FIRST 8 PARTS OF HASHED )
This approach ensures that usernames are unique, reducing the chances of conflicts during user registration.

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution @Manancode.

This patch seems to assume the username is always going to be an email, which is not the case, which may be problematic.

A test cases for this use case is missing.

integrity sha512-lFMjJTrFL3j7L9yBxwYfCq2k6qqwHyzuUl/XBnif78PWTJYyL/dfowQHWE3sp6U6ZzqWiiIZnpTMO96zhkjwtg==
dependencies:
"@jridgewell/gen-mapping" "^0.3.0"
"@jridgewell/trace-mapping" "^0.3.9"

"@babel/cli@^7.10.1":
version "7.17.10"
resolved "https://registry.yarnpkg.com/@babel/cli/-/cli-7.17.10.tgz#5ea0bf6298bb78f3b59c7c06954f9bd1c79d5943"
resolved "https://registry.npmjs.org/@babel/cli/-/cli-7.17.10.tgz"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not change these lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants