Feat: Password Generator - #222
Merged
Merged
Conversation
Signed-off-by: Jeel Dobariya <jeeldobariya38@gmail.com>
| DEFAULT_PASSWORD_OPTIONS, | ||
| ); | ||
|
|
||
| const [password, setPassword] = useState(() => |
Member
Author
There was a problem hiding this comment.
@razorblade23 can pls suggest what can be done? Is ai correct or my version is just fine cuz, i thing we just generating password here so if the crypto is predictable it okay i guess
Member
There was a problem hiding this comment.
AI is right, you should never use basic random generator for something secure, like passwords.
In node, you can use randomInt from node.crypto module as in this example (generated with AI - use caution):
import { randomInt } from 'node:crypto';
/**
* Generates a cryptographically secure random password.
* @param {number} length - The length of the password (default: 16).
* @returns {string} The generated password.
*/
export function generateSecurePassword(length = 16) {
const lowercase = 'abcdefghijklmnopqrstuvwxyz';
const uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const numbers = '0123456789';
const symbols = '!@#$%^&*()_+-=[]{}|;:,.<>?';
const charset = lowercase + uppercase + numbers + symbols;
let password = '';
for (let i = 0; i < length; i++) {
// randomInt securely picks an index between 0 (inclusive) and charset.length (exclusive)
const randomIndex = randomInt(0, charset.length);
password += charset.charAt(randomIndex);
}
return password;
}
// Example usage:
const securePassword = generateSecurePassword(18);
console.log(securePassword); FYI - save this below
A very good article to read on Android Security practices
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes Made
Notes
thanks to @jainil63 for contributing the password generator code under the event of "Beginner Fest | Contribution Race" in discord.