From de29536fa1fc8d57c522637250c294027cb4ebef Mon Sep 17 00:00:00 2001 From: LV-426 Date: Tue, 13 Jan 2015 01:52:35 +0200 Subject: mv init_pw_db to rz_cli_tool, improve --- src/server/crypt_util.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'src/server/crypt_util.py') diff --git a/src/server/crypt_util.py b/src/server/crypt_util.py index 464fac94..7eec4c57 100644 --- a/src/server/crypt_util.py +++ b/src/server/crypt_util.py @@ -1,23 +1,17 @@ -import pickle import hashlib, uuid -import os import logging +import pickle -log = logging.getLogger('rhizi') -def add_user_login(config, u, p): - htpasswd_path = config.htpasswd_path +log = logging.getLogger('rhizi') - if False == os.path.exists(htpasswd_path): - with open(htpasswd_path, 'wb') as f: - pickle.dump({}, f) +def add_user_login(htpasswd_path, salt, u, p): with open(htpasswd_path, 'rb') as f: data = f.read() pw_db = pickle.loads(data) with open(htpasswd_path, 'wb') as f: - salt = config.secret_key pw_db[u] = hash_pw(str(p), salt) pickle.dump(pw_db, f) @@ -38,9 +32,9 @@ def validate_login(config, u, p): existing_pw_hash = pw_db.get(u) if None == existing_pw_hash: - raise Exception('Not autorhized') + raise Exception('Not authorized') if hash_pw(p, salt) != existing_pw_hash: - raise Exception('Not autorhized') + raise Exception('Not authorized') -- cgit v1.3.1