Mercurial > p > roundup > code
comparison roundup/password.py @ 5415:2d6a92c3e212
Python 3 preparation: use string.ascii_letters instead of string.letters.
| author | Joseph Myers <jsm@polyomino.org.uk> |
|---|---|
| date | Wed, 25 Jul 2018 00:40:26 +0000 |
| parents | 3fa026621f69 |
| children | 56c9bcdea47f |
comparison
equal
deleted
inserted
replaced
| 5414:3fa026621f69 | 5415:2d6a92c3e212 |
|---|---|
| 176 s = md5(plaintext).hexdigest() | 176 s = md5(plaintext).hexdigest() |
| 177 elif scheme == 'crypt' and crypt is not None: | 177 elif scheme == 'crypt' and crypt is not None: |
| 178 if other is not None: | 178 if other is not None: |
| 179 salt = other | 179 salt = other |
| 180 else: | 180 else: |
| 181 saltchars = './0123456789'+string.letters | 181 saltchars = './0123456789'+string.ascii_letters |
| 182 salt = random.choice(saltchars) + random.choice(saltchars) | 182 salt = random.choice(saltchars) + random.choice(saltchars) |
| 183 s = crypt.crypt(plaintext, salt) | 183 s = crypt.crypt(plaintext, salt) |
| 184 elif scheme == 'plaintext': | 184 elif scheme == 'plaintext': |
| 185 s = plaintext | 185 s = plaintext |
| 186 else: | 186 else: |
| 187 raise PasswordValueError('Unknown encryption scheme %r'%scheme) | 187 raise PasswordValueError('Unknown encryption scheme %r'%scheme) |
| 188 return s | 188 return s |
| 189 | 189 |
| 190 def generatePassword(length=12): | 190 def generatePassword(length=12): |
| 191 chars = string.letters+string.digits | 191 chars = string.ascii_letters+string.digits |
| 192 password = [random.choice(chars) for x in range(length)] | 192 password = [random.choice(chars) for x in range(length)] |
| 193 # make sure there is at least one digit | 193 # make sure there is at least one digit |
| 194 password[0] = random.choice(string.digits) | 194 password[0] = random.choice(string.digits) |
| 195 random.shuffle(password) | 195 random.shuffle(password) |
| 196 return ''.join(password) | 196 return ''.join(password) |
