Exemplo n.º 1
0
def addUser(username, pwhash, groupid):
    salted_hash = doSalt(pwhash)
    cur = dbservices.getCursor()


    sql = "INSERT INTO `users` (`username`, `password`, `group_id`) VALUES(%s, %s, %s)"
    cur.execute(sql, (username, salted_hash, groupid))
    dbservices.closeCursor(cur)
    logging.info("User %s added to group %i", username, groupid)
Exemplo n.º 2
0
def editUser(orig_username, username, pwhash, groupid):
    sql = "UPDATE `users` SET `username` = %s, `password` = %s, `group_id` = %s WHERE `username` = %s"
    cur = dbservices.getCursor()
    rows_affected = cur.execute(sql, (username, doSalt(pwhash), groupid, orig_username))
    dbservices.closeCursor(cur)
    if rows_affected:
        logging.info("User %s edited: Group %s", username, groupid)
        return True
    logging.info("User %s editing failed", username)
    return False
Exemplo n.º 3
0
def deleteUser(username):
    sql = "DELETE FROM `users` WHERE username = %s"
    cur = dbservices.getCursor()
    rows_affected = cur.execute(sql, username)
    dbservices.closeCursor(cur)
    if rows_affected:
        logging.info("User %s deleted.", username)
        return True
    logging.info("User %s deletion failed.", username)
    return False
Exemplo n.º 4
0
def checkIfUsernameExists(username):
    cur = dbservices.getCursor()

    sql = "SELECT COUNT(*) FROM `users` WHERE `username` = %s"
    cur.execute(sql, username)
    numEntries = cur.fetchone()[0]
    
    dbservices.closeCursor(cur)

    if numEntries:
        return True
    return False
Exemplo n.º 5
0
def loginUser(username, pwhash):
    salted_hash = doSalt(pwhash)
    
    sql = "SELECT COUNT(*) FROM `users` WHERE username = %s AND password = %s"
    
    cur = dbservices.getCursor()
    cur.execute(sql, (username, salted_hash))
    numrows = cur.fetchone()[0]
    dbservices.closeCursor(cur)
    if numrows:
        logging.info("User %s successfully logged in", username)
        return True
    logging.info("User %s login attempt failed", username)
    return False