How to generate random password with PHP?

后端 未结 19 2228
栀梦
栀梦 2020-12-01 00:45

Or is there a software to auto generate random passwords?

19条回答
  •  生来不讨喜
    2020-12-01 01:15

    Another, very simple (and secure!) way to do this is the following (I generate all my own passwords that way):

    base64_encode(random_bytes(12));
    

    This generates a 16 character password that uses quite a sane range of characters.

    However, depending on your requirements (for example if a user needs to type in their password), it may be desirable to remove characters that migth be confused (such as l, I, 1, 0, O, 5, S, and so on). In that case, the above solution is probably a bit too simple.

提交回复
热议问题