comparison roundup/password.py @ 6638:e1588ae185dc issue2550923_computed_property

merge from default branch. Fix travis.ci so CI builds don't error out
author John Rouillard <rouilj@ieee.org>
date Thu, 21 Apr 2022 16:54:17 -0400
parents 120b0bb05b6e
children 469ad03e6cb8
comparison
equal deleted inserted replaced
6508:85db90cc1705 6638:e1588ae185dc
199 s = ssha(s2b(plaintext), salt) 199 s = ssha(s2b(plaintext), salt)
200 elif scheme == 'SHA': 200 elif scheme == 'SHA':
201 s = sha1(s2b(plaintext)).hexdigest() # nosec 201 s = sha1(s2b(plaintext)).hexdigest() # nosec
202 elif scheme == 'MD5': 202 elif scheme == 'MD5':
203 s = md5(s2b(plaintext)).hexdigest() # nosec 203 s = md5(s2b(plaintext)).hexdigest() # nosec
204 elif scheme == 'crypt' and crypt is not None: 204 elif scheme == 'crypt':
205 if crypt is None:
206 raise PasswordValueError(
207 'Unsupported encryption scheme %r' % scheme)
205 if other is not None: 208 if other is not None:
206 salt = other 209 salt = other
207 else: 210 else:
208 saltchars = './0123456789'+string.ascii_letters 211 saltchars = './0123456789'+string.ascii_letters
209 salt = random_.choice(saltchars) + random_.choice(saltchars) 212 salt = random_.choice(saltchars) + random_.choice(saltchars)
353 """Stringify the encrypted password for database storage.""" 356 """Stringify the encrypted password for database storage."""
354 if self.password is None: 357 if self.password is None:
355 raise ValueError('Password not set') 358 raise ValueError('Password not set')
356 return '{%s}%s' % (self.scheme, self.password) 359 return '{%s}%s' % (self.scheme, self.password)
357 360
361 def test_missing_crypt():
362 p = encodePassword('sekrit', 'crypt')
358 363
359 def test(): 364 def test():
360 # SHA 365 # SHA
361 p = Password('sekrit') 366 p = Password('sekrit')
362 assert Password(encrypted=str(p)) == 'sekrit' 367 assert Password(encrypted=str(p)) == 'sekrit'
413 assert 'not sekrit' != p 418 assert 'not sekrit' != p
414 419
415 420
416 if __name__ == '__main__': 421 if __name__ == '__main__':
417 test() 422 test()
423 test_missing_crypt()
418 424
419 # vim: set filetype=python sts=4 sw=4 et si : 425 # vim: set filetype=python sts=4 sw=4 et si :

Roundup Issue Tracker: http://roundup-tracker.org/