diff options
author | Lukas Fleischer <archlinux@cryptocrack.de> | 2014-02-06 16:06:04 +0100 |
---|---|---|
committer | Lukas Fleischer <archlinux@cryptocrack.de> | 2014-02-06 18:59:40 +0100 |
commit | 0722f46c6e5e1a1bae85c24379ff061025679c1d (patch) | |
tree | 0d891201ca85fd80a30073b0e27d57161fca7c11 /web/lib/acctfuncs.inc.php | |
parent | 3f0a1a827a1b26e3714eef3cf405b6f99f22e9af (diff) | |
download | aur-0722f46c6e5e1a1bae85c24379ff061025679c1d.tar.gz aur-0722f46c6e5e1a1bae85c24379ff061025679c1d.tar.xz |
Simplify valid_user() and valid_username()
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
Diffstat (limited to 'web/lib/acctfuncs.inc.php')
-rw-r--r-- | web/lib/acctfuncs.inc.php | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index 49d7d7c9..f7055740 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -537,17 +537,14 @@ function is_ipbanned() { * @return bool True if username meets criteria, otherwise false */ function valid_username($user) { - if (!empty($user)) { - if ( strlen($user) >= USERNAME_MIN_LEN && - strlen($user) <= USERNAME_MAX_LEN ) { - $user = strtolower($user); - if ( preg_match("/^[a-z0-9]+[.\-_]?[a-z0-9]+$/", $user) ) { - return true; - } - } + if (strlen($user) < USERNAME_MIN_LEN || + strlen($user) > USERNAME_MAX_LEN) { + return false; + } else if (!preg_match("/^[a-z0-9]+[.\-_]?[a-z0-9]+$/", $user)) { + return false; } - return false; + return true; } /** @@ -558,21 +555,17 @@ function valid_username($user) { * @return string|void Return user ID if in database, otherwise void */ function valid_user($user) { - /* if ( $user = valid_username($user) ) { */ - - $dbh = DB::connect(); - - if ( $user ) { - $q = "SELECT ID FROM Users "; - $q.= "WHERE Username = " . $dbh->quote($user); + if ($user) { + $dbh = DB::connect(); + $q = "SELECT ID FROM Users WHERE "; + $q.= "Username = " . $dbh->quote($user); $result = $dbh->query($q); if ($result) { $row = $result->fetch(PDO::FETCH_NUM); return $row[0]; } } - return; } /** |