High quality, simple random password generator

前端 未结 27 2583
渐次进展
渐次进展 2020-12-22 17:06

I\'m interested in creating a very simple, high (cryptographic) quality random password generator. Is there a better way to do this?

import os, random, strin         


        
27条回答
  •  难免孤独
    2020-12-22 17:17

    Implenting @Thomas Pornin solution (can't comment @Yossi inexact answer):

    import string, os
    chars = string.ascii_letters + string.digits + '+/'
    assert 256 % len(chars) == 0  # non-biased later modulo
    PWD_LEN = 16
    print(''.join(chars[c % len(chars)] for c in os.urandom(PWD_LEN)))
    

    UPDATED for python3 thank to Stephan Lukits

提交回复
热议问题