def test_no_verify(self): """ Verification fails with wrong password """ settings = { 'user.u1': pwd_context.encrypt('foobar'), } backend = self._backend(settings) valid = backend.verify_user('u1', 'foobarz') self.assertFalse(valid)
def test_verify(self): """ Users can log in with correct password """ settings = { 'user.u1': pwd_context.encrypt('foobar'), } backend = self._backend(settings) valid = backend.verify_user('u1', 'foobar') self.assertTrue(valid)
def _gen_password(): """ Prompt user for a password twice for safety """ while True: password = getpass.getpass() verify = getpass.getpass() if password == verify: return pwd_context.encrypt(password) else: six.print_("Passwords do not match!")
def _gen_password(): """ Prompt user for a password twice for safety """ while True: password = getpass.getpass() verify = getpass.getpass() if password == verify: return pwd_context.encrypt(password) else: print "Passwords do not match!"
def load_read_user(): if 'READ_USER' in os.environ and 'READ_USER_PASSWORD' in os.environ: return { 'read_user': os.environ['READ_USER'], 'read_user_password': pwd_context.encrypt(os.environ['READ_USER_PASSWORD']), } return {}
def make_config(): """ env = ['dev', test, prod] :return: """ env = os.environ['ENV'] assert env in ['dev', 'test', 'prod'], "ENV must be dev/test/prod" username = os.environ['ADMIN_USERNAME'] password = os.environ['ADMIN_PASSWORD'] outfile = 'server.ini' storage = os.environ['STORAGE'] assert storage in ['s3', 'file'], "STORAGE must be s3/file" session_secure = os.environ.get('SESSION_SECURE') if not session_secure: session_secure = env == 'prod' data = { 'env': env, 'reload_templates': env == 'dev', 'storage': storage, 'encrypt_key': b64encode(os.urandom(32)), 'validate_key': b64encode(os.urandom(32)), 'admin': username, 'password': pwd_context.encrypt(password), 'session_secure': session_secure, } data.update(load_read_user()) if storage == 's3': data.update(load_s3_params()) if env == 'dev' or env == 'test': data['wsgi'] = 'waitress' else: if hasattr(sys, 'real_prefix'): data['venv'] = sys.prefix data['wsgi'] = 'uwsgi' current_folder = abspath(dirname(__file__)) template_file = join(current_folder, 'config.ini.jinja2') tmpl_str = open(template_file).read() template = Template(tmpl_str) config_file = template.render(**data) with open(outfile, 'w') as ofile: ofile.write(config_file) print "Config file written to '%s'" % outfile
def make_user(name, password, pending=True): """ Convenience method for creating a User """ return User(name, pwd_context.encrypt(password), pending)