示例#1
0
def add_admin(username, password):
    """
    Adds an admin to the database

    Params:
        username - A string containing the admin's username
        password - A string containing the admin's password

    Returns:
        None
    """
    init_tables()
    conn = sqlite3.connect(DB_NAME)
    c = conn.cursor()
    PARAMS = (username, hash.password_hash(password))
    c.execute(INSERT_QUERY, PARAMS)
    conn.commit()
    conn.close()
    return
示例#2
0
def admin_exists(username, password):
    """
    Check if an admin with specified username and password exists in the
    database

    Params:
        username - A string containing the admin's username
        password - A string containing the admin's password

    Returns:
        True if the specified admin exists (exactly once) in the database,
        False otherwise
    """
    init_tables()
    conn = sqlite3.connect(DB_NAME)
    c = conn.cursor()
    PARAMS = (username , hash.password_hash(password))
    result = list(c.execute(SELECT_QUERY, PARAMS))
    conn.close()
    return len(result) == 1 # If > 1, then duplicate users
示例#3
0
 def set_password(self, password, salt=None):
     self.__hashed_password = password_hash(password, salt)