Пример #1
0
def import_user_sqlite3(data):
    import sqlite3
    db = sqlite3.connect(db_conf['default:db_path'])
    cursor = db.cursor()
    cursor.execute('BEGIN')
    data['pwd_hash'] = mk_pwd_hash_default(
        data['pwd']) if data['pwd'] else None
    del data['pwd']
    cursor.execute('INSERT INTO data (key, value, expires) VALUES (?, ?, -1)',
                   ('corplist:user:{0}'.format(data['id']),
                    json.dumps(data.get('permitted_corpora', []))))
    del data['permitted_corpora']
    cursor.execute('INSERT INTO data (key, value, expires) VALUES (?, ?, -1)',
                   ('user:{0}'.format(data['id']), json.dumps(data)))
    cursor.execute('SELECT value FROM data WHERE key = ?', ('user_index', ))
    tmp = cursor.fetchone()
    if not tmp:
        uindex = {}
    else:
        uindex = json.loads(tmp[0])
    uindex[data['username']] = 'user:{0}'.format(data['id'])

    cursor.execute(
        'INSERT OR REPLACE INTO data (key, value, expires) VALUES (?, ?, -1)',
        ('user_index', json.dumps(uindex)))
    cursor.execute('COMMIT')
    print(('Installed user {}'.format(data['username'])))
Пример #2
0
 def test_make_and_split_default_hash(self):
     """
     hash a password using the default values, then split the returned hash string and check whether correct
     information is present
     """
     hashed_def = mk_pwd_hash_default('password')
     split_def = split_pwd_hash(hashed_def)
     keys = ['algo', 'salt', 'iterations', 'data', 'keylen']
     for key in keys:
         self.assertTrue(key in split_def)
Пример #3
0
 def add_user(self, idx, username, pwd, firstname, lastname, email=None):
     self.user_index[username] = "user:"******"user:" + str(idx),
         dict(id=idx,
              username=username,
              firstname=firstname,
              lastname=lastname,
              email=email,
              pwd_hash=mk_pwd_hash_default(pwd)))
Пример #4
0
 def add_user_dict(self, user):
     self.user_index[user.get('username')] = "user:"******"user:"******"user:" + str(user.get('id')),
              username=user.get('username'),
              firstname=user.get('firstname'),
              lastname=user.get('lastname'),
              email=user.get('email'),
              pwd_hash=password))
Пример #5
0
def import_user_redis(data):
    import redis
    db = redis.StrictRedis(host=db_conf['default:host'],
                           port=db_conf['default:port'],
                           db=db_conf['default:id'])
    data['pwd_hash'] = mk_pwd_hash_default(
        data['pwd']) if data['pwd'] else None
    del data['pwd']
    db.set('corplist:user:{0}'.format(data['id']),
           json.dumps(data.get('permitted_corpora', [])))
    del data['permitted_corpora']
    db.set('user:{0}'.format(data['id']), json.dumps(data))
    db.hset('user_index', data['username'],
            json.dumps('user:{0}'.format(data['id'])))
    print(('Installed user {}'.format(data['username'])))
Пример #6
0
import os
import sys
import random
import string

sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../lib'))

from plugins.default_auth.tools import mk_pwd_hash_default

random = ''.join(
    [random.choice(string.ascii_letters + string.digits) for n in range(8)])
print(random + "-" + mk_pwd_hash_default(random))