DEV Community

Discussion on: How to create a password generator using react

inhuofficial profile image
InHuOfficial • Edited

There is an error in your code:

const characterIndex = Math.round(Math.random() * CharacterListLength);

It should be Math.floor otherwise you may end up with an index the same as the CharacterListLength and that would be an invalid index.

Also it is a good practice to share a jsfiddle codepen etc so people can play with your code.

Either way, it looks nice! ❤

yoursunny profile image
Junxiao Shi

Math.random() is not cryptographically secure and must not be used to generate passwords.
Instead, use Crypto.getRandomValues().

aman2221 profile image
Aman Singh Author • Edited

Thank you so much bro
now it's working properly