Example #1
0
def insert_into_clients(username, password):
    insert_sql = '''INSERT INTO clients (username, password, salt)
                         VALUES (?, ?, ?)'''
    hashed_password, salt = hash_pass(password)

    cursor.execute(insert_sql, (username, hashed_password, salt))
    conn.commit()
Example #2
0
def change_pass(new_pass, logged_user):
    update_sql = '''UPDATE clients
                    SET password = ?, salt = ?
                    WHERE id = ?'''
    pwd_hash, salt = hash_pass(new_pass)
    cursor.execute(update_sql, (pwd_hash, salt, logged_user.get_id(),))
    conn.commit()
Example #3
0
def _login(username, password):
    salt_query = '''SELECT username, salt, password
                    FROM clients
                    WHERE username = ?
                    LIMIT 1'''
    cursor.execute(salt_query, (username,))
    auth_result = cursor.fetchone()

    if auth_result is None:
        return False

    pwd_hash, _ = hash_pass(password, salt=auth_result['salt'])

    select_query = '''SELECT id, username, balance, message
                      FROM clients
                      WHERE username = ?
                      AND password = ?
                      LIMIT 1'''

    cursor.execute(select_query, (username, pwd_hash))
    user = cursor.fetchone()

    if(user):
        return Client(user[0], user[1], user[2], user[3])
    else:
        return False
Example #4
0
 def login(self, email, password):
     hashed_pass, salt = hash_pass(password)
     user = self.session.query(Client).\
             filter(Client.email == email,
                    Client.password == hashed_pass,
                    Client.salt == salt).first()
     if user:
         return Client(email=email, name=user.name,
                         password=hashed_pass, salt=salt)
     else:
         raise NoSuchCLient('There is no such client.')
Example #5
0
    def change_password(self, new_password, logged_user):
        user = self.session.query(Client).\
                filter(Client.email == logged_user.email).first()

        if user is None:
            raise NoSuchCLient('There is no such client.')

        hashed_pass, salt = hash_pass(new_password)

        user.password = hashed_pass
        user.salt = salt
        self.__commit()
Example #6
0
    def register(self, email, name, password):
        user = self.session.query(Client).\
                filter(Client.email == email).first()

        if user is not None:
            raise ClientAlreadyRegistered('Client already registered.')

        if not get_validator(email.split("@")[0]).is_valid(password):
            raise PasswordNotStrongError

        if not email_validation(email):
            raise EmailNotValidError

        hashed_pass, salt = hash_pass(password)

        client = Client(email=email, name=name, password=hashed_pass, salt=salt)
        self.__commit_object(client)