High quality, simple random password generator

前端 未结 27 2365
渐次进展
渐次进展 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:16

    implementing @Thomas Pornin solution

    import M2Crypto
    import string
    
    def random_password(length=10):
        chars = string.ascii_uppercase + string.digits + string.ascii_lowercase
        password = ''
        for i in range(length):
            password += chars[ord(M2Crypto.m2.rand_bytes(1)) % len(chars)]
        return password
    

提交回复
热议问题