DEV Community

Discussion on: How to create a password generator using react

Collapse
 
grahamthedev profile image
GrahamTheDev • 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! ❤

Collapse
 
yoursunny profile image
Junxiao Shi

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

Collapse
 
aman2221 profile image
Aman Singh • Edited

Thank you so much bro
now it's working properly