auth.h 1.3 KB

123456789101112131415161718192021222324252627282930
  1. #ifndef AUTH_H_
  2. #define AUTH_H_
  3. #include "sqlite3.h"
  4. #include "list.h"
  5. #define BCRYPT_ROUNDS 12
  6. #define MAXLEN_RESULT 128
  7. #define MAXLEN_PERM 32
  8. #define MAXLEN_PASSWORD 72
  9. #define MAXLEN_PASSHASH 64
  10. #define MAXLEN_SALT (LEN_SALT+1)
  11. #define LEN_SALT 64 //Length of salt
  12. typedef struct authdb {
  13. char* path; //Path to SQLite database file
  14. sqlite3* conn; //Database connection "object"
  15. } authdb;
  16. void init_prng(); //Initialize the dSFMT PRNG
  17. authdb* new_authdb(char* path); //Open a new auth database object, creating and initializing if it doesn't exist
  18. int register_perm(authdb *db, char* perm, char* desc); //Create a new permission
  19. int register_group(authdb *db, char* groupname); //Create a new group
  20. int user_addperm(authdb* db, char* username, char* perm); //Assign a permission to a user
  21. int user_has_perm(authdb* db, char* user, char* perm); //Return 0 if user is assigned permission, 1 otherwise
  22. int user_setpass(authdb *db, char* username, char* password); //Change users password
  23. int user_validate(authdb *db, char* username, char* password); //Return 0 if password matches DB record
  24. int register_user(authdb *db, char* username, char* password, char* groupname, ...); //Create a new user
  25. #endif