Generate random password string with requirements in javascript

前端 未结 20 1721
夕颜
夕颜 2020-12-07 07:56

I want to generate a random string that has to have 5 letters from a-z and 3 numbers.

How can I do this with JavaScript?

I\'ve got the following script, but

20条回答
  •  情歌与酒
    2020-12-07 08:06

    Any password generated with Math.random() is EXTREMELY BAD.

    This function uses the system time as a seed for the random number generator. Anyone who knows the time the password was generated can easily brute-force the password.

    In almost all cases, this data is easily available - just take the registration_time column in a hacked database, and test out all the values generated by the Math.random() algorithm using the times from 15 to 0 minutes before.

    A password generated with Math.random() is completely worthless because the time the password was first used is enough for cracking it.

提交回复
热议问题