Question Overflow
Question Overflow

Reputation: 11255

Generating a Random Password containing both Numbers and Letters

I want to generate a random password of 15 characters that contains BOTH numbers and letters. Is there a simple way to do this?

I want to avoid a situation where I get all numbers in the password, but do not want to prefix the password with any letters.

Upvotes: 0

Views: 1268

Answers (4)

Mob
Mob

Reputation: 11098

How about this? Generates a highly random alphanumeric password of 15 chars.

$p = substr ( md5(uniqid(rand(), true)), 0, 15);

Upvotes: 0

Parag Chaure
Parag Chaure

Reputation: 3005

you can generate the password in a loop till the length of password string you want. You can use rand() function within it to avoid the continues characters you can also use ASCII code for it with char() function

Upvotes: 0

Blem
Blem

Reputation: 822

Generate an array with a random number, a random character and 13 random chars/numbers and then use shuffle

Upvotes: 1

str
str

Reputation: 44969

You could use:

$pw = substr(md5(uniqid()), 0, 15);

I think it's very unlikely to end up with all numbers with this approach.

Upvotes: 1

Related Questions