Skip to content

Commit

Permalink
db.d: enforce unique usernames (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
slook authored Aug 17, 2024
1 parent 2da8f21 commit bf95d7a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/db.d
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class Sdb
const string admins_table = "admins";
const string conf_table = "conf";

const string users_table_format = "CREATE TABLE %s(username TEXT, password TEXT, speed INTEGER, ulnum INTEGER, files INTEGER, folders INTEGER, banned INTEGER, privileges INTEGER);";
const string admins_table_format = "CREATE TABLE %s(username TEXT, level INTEGER);";
const string users_table_format = "CREATE TABLE %s(username TEXT PRIMARY KEY, password TEXT, speed INTEGER, ulnum INTEGER, files INTEGER, folders INTEGER, banned INTEGER, privileges INTEGER) WITHOUT ROWID;";
const string admins_table_format = "CREATE TABLE %s(username TEXT PRIMARY KEY, level INTEGER) WITHOUT ROWID;";
const string conf_table_format = "CREATE TABLE %s(port INTEGER, max_users INTEGER, motd TEXT);";

this(string file, bool update = false)
Expand Down Expand Up @@ -89,7 +89,7 @@ class Sdb

void add_admin(string username, uint level = 0)
{
this.query(format("INSERT INTO %s(username, level) VALUES('%s', %d);", admins_table, escape(username), level));
this.query(format("REPLACE INTO %s(username, level) VALUES('%s', %d);", admins_table, escape(username), level));
}

void del_admin(string username)
Expand Down

0 comments on commit bf95d7a

Please sign in to comment.