Exemplo n.º 1
0
def check_user(username):
    """ 
    @summary: 校验用户名和密码
    @param username: 用户名
    @return: True/False
    """
    db = None
    count = 0
    try:
        db = DBHelper()
        sql = "select count(*) from user_list where username=%s"
        data = db.query_one(sql, username)
        count = data[0]
    except Exception as e:
        logger.debug('check user failure:' + str(e) + '. ' + traceback.format_exc())
        raise
    finally:
        if db:
            db.release()

    return count == 1
Exemplo n.º 2
0
def validate_user(username, password):
    """ 
    @summary: 校验用户名和密码
    @param username: 用户名
    @param password: 密码
    @return: True/False
    """
    db = None
    count = 0
    try:
        db = DBHelper()
        sql = "select count(*) from user_list where username=%s and password=%s"
        data = db.query_one(sql, (username, hashlib.sha256(str(password).encode('utf-8')).hexdigest()))
        count = data[0]
    except Exception as e:
        logger.debug('validate user failure:' + str(e) + '. ' + traceback.format_exc())
        raise
    finally:
        if db:
            db.release()
    return count == 1