<commit_before>import os

import hashlib

import asyncio
import aiopg

import nwdb
import core
import mailqueue


@core.function
def authenticate(client, email, password):
    """
    Authenticate the client by matching email and password.
    Note, the password must not be sent in cleartext, it is sent as a
    sha356(uid + sha256(password)), where uid is sent with the initial
    welcome message.
    """
    hash = client.uid
    with (yield from nwdb.connection()) as conn:
        cursor = yield from conn.cursor()
        yield from cursor.execute("""
        select A.id, A.handle, A.email, A.password, A.clan_id, A.roles, B.name
        from member A
        left outer join clan B on B.id = A.clan_id
        where lower(A.email) = lower(%s)
        """, [email])
        rs = yield from cursor.fetchone()
        authenticated = False
        roles = []
        if rs is None:
            authenticated = False
        else:
            h = (hash + rs[3]).encode("utf8")
            if hashlib.sha256(h).hexdigest() == password:
                client.member_id = client.session["member_id"] = rs[0]
                client.roles = list(rs[5])
                authenticated = True
                if 'Banned' in client.roles:
                    yield from client.send("auth.banned")
                    authenticated = False
            else:
                authenticated = False
        if(not authenticated):
            yield from asyncio.sleep(3)
        client.authenticated = authenticated
        if authenticated:
            yield from client.send("auth.info", dict(id=rs[0], handle=rs[1], roles=roles, clan_id=rs[4], clan_name=rs[6]))
        return authenticated


@core.function
def register(client, handle, email, password):
    """
    Register a new user. Handle and email must be unique, and password
    must be <PASSWORD>256(password), not cleartext.
    """
    with (yield from nwdb.connection()) as conn:
        cursor = yield from conn.cursor()
        try:
            yield from cursor.execute("""
            insert into member(handle, email, password)<commit_msg>added extra metadata to client<commit_after>import os

import hashlib

import asyncio
import aiopg

import nwdb
import core
import mailqueue


@core.function
def authenticate(client, email, password):
    """
    Authenticate the client by matching email and password.
    Note, the password must not be sent in cleartext, it is sent as a
    sha356(uid + sha256(password)), where uid is sent with the initial
    welcome message.
    """
    hash = client.uid
    with (yield from nwdb.connection()) as conn:
        cursor = yield from conn.cursor()
        yield from cursor.execute("""
        select A.id, A.handle, A.email, A.password, A.clan_id, A.roles, B.alliance_id
        from member A
        left outer join clan B on B.id = A.clan_id
        where lower(A.email) = lower(%s)
        """, [email])
        rs = yield from cursor.fetchone()
        authenticated = False
        roles = []
        if rs is None:
            authenticated = False
        else:
            h = (hash + rs[3]).encode("utf8")
            if hashlib.sha256(h).hexdigest() == password:
                client.member_id = client.session["member_id"] = rs[0]
                client.roles = list(rs[5])
                client.clan_id = rs[4]
                client.alliance_id = rs[6]
                authenticated = True
                if 'Banned' in client.roles:
                    yield from client.send("auth.banned")
                    authenticated = False
            else:
                authenticated = False
        if(not authenticated):
            yield from asyncio.sleep(3)
        client.authenticated = authenticated
        if authenticated:
            yield from client.send("auth.info", dict(id=rs[0], handle=rs[1], roles=roles, clan_id=rs[4], clan_name=rs[6]))
        return authenticated


@core.function
def register(client, handle, email, password):
    """
    Register a new user. Handle and email must be unique, and password
    must be <PASSWORD>256(password), not cleartext.
    """
    with (yield from nwdb.connection()) as conn:
        cursor = yield from conn.cursor()
        try:
            yield from cursor.execute("""
            insert into member(handle, email, password)
{'fraction_non_alphanumeric': 0.09967547519703292, 'fraction_numerical': 0.010199350950394067, 'mean_word_length': 2.1110310021629415, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7415433', 'n_tokens_mistral': 1262, 'n_tokens_neox': 1204, 'n_words': 387}