Skip to content

Conversation

SebinSong
Copy link
Collaborator

@SebinSong SebinSong commented Jul 8, 2025

closes #2849

Below is the updated sign-up form:

@taoeffect Currently the random-generated password is always 32 characters long (32 here is just an arbitrary number I chose), but let me know if you have other opinions re this behavior.

@SebinSong SebinSong self-assigned this Jul 8, 2025
Copy link

cypress bot commented Jul 8, 2025

group-income    Run #4769

Run Properties:  status check passed Passed #4769  •  git commit 1692dab853 ℹ️: Merge 3a351738c87f23d791bd4ad80bcdab701f38b99f into 93de1fea25b9775499a6e7ce5cc0...
Project group-income
Branch Review sebin/task/#2849-random-generated-password
Run status status check passed Passed #4769
Run duration 14m 12s
Commit git commit 1692dab853 ℹ️: Merge 3a351738c87f23d791bd4ad80bcdab701f38b99f into 93de1fea25b9775499a6e7ce5cc0...
Committer Sebin Song
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 10
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 116
View all changes introduced in this branch ↗︎

@taoeffect taoeffect requested a review from corrideat July 16, 2025 18:57
generateRandomPassword (pwLen = 32) {
let genPassword = ''
if (window?.Cypress) {
Copy link
Member

Choose a reason for hiding this comment

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

I'd use process.env.CI here. If this code makes it to production and someone is using Cypress or some extension that defines Cypress, we wouldn't want to accidentally use a weak password.

Also, not sure why window?, since it should always be defined.

Copy link
Collaborator Author

@SebinSong SebinSong Aug 4, 2025

Choose a reason for hiding this comment

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

will remove ? typo here. Correct me if I'm wrong but process.env.CI is only true when tested as part of GH action workflow?

}
},
methods: {
generateRandomPassword (pwLen = 32) {
Copy link
Member

Choose a reason for hiding this comment

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

Based on the crypto primitives we use for encryption, I think 128 bits (i.e., 32 chars long passwords, assuming hex) is a reasonable value.

const bytes = new Uint8Array(Math.ceil(pwLen / 2))
crypto.getRandomValues(bytes)
genPassword = Array.from(bytes).map(b => b.toString(36) // [0-9a-z] => 36 characters
Copy link
Member

Choose a reason for hiding this comment

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

This choice of alphabet together with how it's done seemed like it'd be prone to bias. After looking at it more closely, it looks fine (as in, the output is biased towards certain characters but I don't think it impacts the entropy in the output).

Copy link
Member

Choose a reason for hiding this comment

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

Coming back to this point: could you consider maybe using base64 or base64url, or even the multiformats library for base58? This way we'd use the larger alphabet more efficiently and have shorter passwords (*) (this is using a 36 character alphabet but still requiring 2 bytes per encoded byte, i.e., about the same efficiency as just using hex)

(*) About 23 characters. Or alternatively, keep the 32-character passwords with more entropy in them, although the extra entropy probably is not needed.

Copy link
Collaborator Author

@SebinSong SebinSong Aug 4, 2025

Choose a reason for hiding this comment

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

@corrideat Updated the PR again to use base58btc from multiformats library. I don't have much knowledge regarding this encode/decode stuff so it was based on my google/chatGPT search. pls write/leave a suggested change for generateBase58Password if any.

Copy link
Member

@corrideat corrideat left a comment

Choose a reason for hiding this comment

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

Looks good. A few general comments summarising my other comments:

  1. I'd use an env variable rather than window.Cypress to avoid accidentally weak passwords
  2. Security-wise it looks fine, but I'd reconsider the choice of alphabet (or encoding) to attain shorter passwords, or to pack more entropy into the existing password length.

@SebinSong
Copy link
Collaborator Author

Thanks @corrideat for reviewing this multiple times!
(I have been busy for something else lately, so will pick this up probably in a few days)

Copy link

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedmultiformats@​13.3.71001001008780

View full report

@SebinSong
Copy link
Collaborator Author

PR is updated again.

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.

Randomly generate user password on Sign Up
2 participants