diff options
author | Malf Furious <m@lfurio.us> | 2019-01-12 22:42:41 -0500 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2019-01-12 22:42:41 -0500 |
commit | d2e4330557e02af6dc4ff133d2586730e94d6959 (patch) | |
tree | 45c1c577dba69cd520b3787dd0300a15fb4cf7ca /app/class/user.class.php | |
parent | f3165d28fff6468fca44ff2ec3b6cfb3fb82ee90 (diff) | |
parent | d71c72ba57abee645daf658bbdb74f296406171d (diff) | |
download | scrott-0.3.tar.gz scrott-0.3.zip |
Merge branch 'rel/v0.3'v0.3
Diffstat (limited to 'app/class/user.class.php')
-rw-r--r-- | app/class/user.class.php | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/app/class/user.class.php b/app/class/user.class.php index 231111d..7d67257 100644 --- a/app/class/user.class.php +++ b/app/class/user.class.php @@ -46,11 +46,12 @@ class user extends agent * the username is not in use. Therefore, this function can be * used to test the existence of a user with the given username. */ - public static function getGuidByUname(string $uname) : ?string + public static function getGuidByUname(string $uname, bool $caseInsens = false) : ?string { $uname = database::esc($uname); - $query = "SELECT guid FROM objects WHERE objtype = 'user' AND name = '" . $uname . "'"; + $query = "SELECT guid FROM objects WHERE objtype = 'user' AND " . + ($caseInsens ? "" : "BINARY ") . "name = '" . $uname . "'"; $res = database::query($query); if (count($res) == 0) @@ -64,9 +65,9 @@ class user extends agent * is not in use. This function can be used to test the existence * of a user with the given username. */ - public static function getByUname(string $uname) : ?user + public static function getByUname(string $uname, bool $caseInsens = false) : ?user { - if (($guid = self::getGuidByUname($uname))) + if (($guid = self::getGuidByUname($uname, $caseInsens))) return new user($guid); return NULL; @@ -190,7 +191,9 @@ class user extends agent */ public static function initNew(string $uname, string $passwd) : ?user { - if (self::getByUname($uname)) + /* search is case-insensitive, to make sure no duplicates exist + * which differ _only_ by case */ + if (self::getByUname($uname, true)) return NULL; $user = new user(); |