#ifndef AUTH_H_
#define AUTH_H_

#include "sqlite3.h"
#include "list.h"

#define BCRYPT_ROUNDS    12
#define MAXLEN_RESULT    128
#define MAXLEN_PERM      32
#define MAXLEN_PASSWORD  72  
#define MAXLEN_PASSHASH  64
#define MAXLEN_SALT      (LEN_SALT+1)
#define LEN_SALT         64  //Length of salt

typedef struct authdb {
  char*     path;   //Path to SQLite database file
  sqlite3*  conn;   //Database connection "object"
} authdb;

void init_prng(); //Initialize the dSFMT PRNG
authdb* new_authdb(char* path); //Open a new auth database object, creating and initializing if it doesn't exist
int register_perm(authdb *db, char* perm, char* desc);         //Create a new permission 
int register_group(authdb *db, char* groupname);               //Create a new group
int user_addperm(authdb* db, char* username, char* perm);      //Assign a permission to a user
int user_has_perm(authdb* db, char* user, char* perm);         //Return 0 if user is assigned permission, 1 otherwise
int user_setpass(authdb *db, char* username, char* password);  //Change users password
int user_validate(authdb *db, char* username, char* password); //Return 0 if password matches DB record
int register_user(authdb *db, char* username, char* password, char* groupname, ...); //Create a new user
#endif
