summaryrefslogtreecommitdiffstats
path: root/web/lib/acctfuncs.inc.php
diff options
context:
space:
mode:
authorLukas Fleischer <archlinux@cryptocrack.de>2014-02-06 16:06:04 +0100
committerLukas Fleischer <archlinux@cryptocrack.de>2014-02-06 18:59:40 +0100
commit0722f46c6e5e1a1bae85c24379ff061025679c1d (patch)
tree0d891201ca85fd80a30073b0e27d57161fca7c11 /web/lib/acctfuncs.inc.php
parent3f0a1a827a1b26e3714eef3cf405b6f99f22e9af (diff)
downloadaurweb-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.php27
1 files changed, 10 insertions, 17 deletions
diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php
index 49d7d7c..f705574 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;
}
/**