def test_crypt_password(password): crypted = crypt_password(password) # it should be a sha512 hash assert crypted.startswith('$6$') # verify password against hash succeeds assert crypt.crypt(password, crypted) == crypted # verify not-the-password against hash fails for not_password in ['', password + ' ', 'hunter3']: assert crypt.crypt(password, crypt_password(not_password)) != crypted
def _get_password(request, addr_name): # If addr_name is None, then this is a wildcard address, and those can't # have passwords. if addr_name is None: return REMOVE_PASSWORD password = request.POST.get('password') if password is not None: password = password.strip() if not password: return REMOVE_PASSWORD try: validate_password(addr_name, password, strength_check=True) except ValueError as ex: _error(request, ex.args[0]) else: return crypt_password(password)