def data2randomChallenge(self, data): ''' build a random challenge according to the challenge definition ''' alphnum = 'abcdefghijklmnopqrstuvwxyz' + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + '0123456789' digits = '0123456789' hex = digits + 'abcdef' challenge = '' c_type = self.Q[0] c_len = self.Q[1] if c_type == 'A': for c in range(0, c_len): challenge += urandom.choice(alphnum) elif c_type == 'N': for c in range(0, c_len): challenge += urandom.choice(digits) elif c_type == 'H': for c in range(0, c_len): challenge += urandom.choice(hex) challenge = challenge[:c_len] return unicode(challenge)
def generate_password(size=6, characters=string.ascii_lowercase + string.ascii_uppercase + string.digits): """ Generate a random password of the specified lenght of the given characters :param size: The length of the password :param characters: The characters the password may consist of :return: password :rtype: basestring """ return "".join(urandom.choice(characters) for _x in range(size))
def generate_password(size=6, characters=string.ascii_lowercase + string.ascii_uppercase + string.digits): """ Generate a random password of the specified lenght of the given characters :param size: The length of the password :param characters: The characters the password may consist of :return: password :rtype: basestring """ return ''.join(urandom.choice(characters) for _x in range(size))
def test_02_choice(self): list = "ABCDEFG" r = urandom.choice(list) self.assertTrue(r in list, r) self.assertTrue("H" != r, r)
def generate_password(size=6, characters=string.ascii_lowercase + string.ascii_uppercase + string.digits): return ''.join(urandom.choice(characters) for _x in range(size))