示例#1
0
def set_auth(username, password, token=None):
    if not password:
        raise ValueError('Password cannot be blank')

    tran = persist_db.transaction()
    if username:
        tran.dict_set('auth', 'username', username)

    salt = base64.b64encode(os.urandom(8))
    pass_hash = base64.b64encode(_hash_password_v1(salt, password))
    tran.dict_set('auth', 'password', '1$%s$%s' % (salt, pass_hash))

    if not token:
        regex = re.compile(r'[\W_]+')
        token = re.sub(regex, '', base64.b64encode(os.urandom(64)))[:32]
        secret = re.sub(regex, '', base64.b64encode(os.urandom(64)))[:32]
        tran.dict_set('auth', 'secret', secret)

    token_salt = base64.b64encode(os.urandom(8))
    token_hash = base64.b64encode(_hash_password_v1(token_salt, token))
    tran.dict_set('auth', 'token', '1$%s$%s' % (token_salt, token_hash))

    username = username or tran.dict_get('auth', 'username')
    token_key_salt = base64.b64encode(os.urandom(8))
    token_key_hash = _hash_password_v2(token_key_salt,
        '%s$%s' % (username, password))
    token_key = token_key_hash

    aes_cipher = Crypto.Cipher.AES.new(token_key)
    token_enc = base64.b64encode(aes_cipher.encrypt(token))
    tran.dict_set('auth', 'token_enc', '2$%s$%s' % (token_key_salt, token_enc))

    tran.commit()
示例#2
0
def set_auth(username, password, token=None):
    if not password:
        raise ValueError("Password cannot be blank")

    tran = persist_db.transaction()
    if username:
        tran.dict_set("auth", "username", username)

    salt = base64.b64encode(os.urandom(8))
    pass_hash = base64.b64encode(_hash_password_v1(salt, password))
    tran.dict_set("auth", "password", "1$%s$%s" % (salt, pass_hash))

    if not token:
        regex = re.compile(r"[\W_]+")
        token = re.sub(regex, "", base64.b64encode(os.urandom(64)))[:32]
        secret = re.sub(regex, "", base64.b64encode(os.urandom(64)))[:32]
        tran.dict_set("auth", "secret", secret)

    token_salt = base64.b64encode(os.urandom(8))
    token_hash = base64.b64encode(_hash_password_v1(token_salt, token))
    tran.dict_set("auth", "token", "1$%s$%s" % (token_salt, token_hash))

    username = username or tran.dict_get("auth", "username")
    token_key_salt = base64.b64encode(os.urandom(8))
    token_key_hash = _hash_password_v2(token_key_salt, "%s$%s" % (username, password))
    token_key = token_key_hash

    aes_cipher = Crypto.Cipher.AES.new(token_key)
    token_enc = base64.b64encode(aes_cipher.encrypt(token))
    tran.dict_set("auth", "token_enc", "2$%s$%s" % (token_key_salt, token_enc))

    tran.commit()
示例#3
0
def set_auth(username=None, password=None):
    tran = persist_db.transaction()
    if username:
        tran.dict_set('auth', 'username', username)
    if password:
        salt = base64.b64encode(os.urandom(8))
        pass_hash = _hash_password_v1(salt, password)
        tran.dict_set('auth', 'password', '1$%s$%s' % (salt, pass_hash))
    tran.commit()