From 6e64691450be0ec2a77fa7c6da74d67f4376db62 Mon Sep 17 00:00:00 2001 From: natrak <> Date: Mon, 18 Jun 2001 20:29:36 +0000 Subject: Changes - Moved account_password() and account_validate() to user.inc. - Greatly reduced the number of SQL calls in account_save() when editing an account. Now uses one db_query() call instead of 1 + (2 * # of access granted). - Fixed access not being saved when account was added. - Should now be possible to edit and add accounts. There were certain bugs before that would cause odd errors. --- includes/user.inc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'includes') diff --git a/includes/user.inc b/includes/user.inc index 0b99a6af5..082bd3f5e 100644 --- a/includes/user.inc +++ b/includes/user.inc @@ -63,4 +63,28 @@ function user_ban($mask, $type) { return db_fetch_object($result); } +function account_password($min_length=6) { + mt_srand((double)microtime() * 1000000); + $words = array("foo","bar","guy","neo","tux","moo","sun","asm","dot","god","axe","geek","nerd","fish","hack","star","mice","warp","moon","hero","cola","girl","fish","java","perl","boss","dark","sith","jedi","drop","mojo"); + while(strlen($password) < $min_length) $password .= $words[mt_rand(0, count($words))]; + return $password; +} + +function account_validate($user) { + // Verify username and e-mail address: + if (empty($user[real_email]) || (!check_mail($user[real_email]))) $error = t("the e-mail address '$user[real_email]' is not valid"); + if (empty($user[userid]) || (!check_name($user[userid]))) $error = t("the username '$user[userid]' is not valid"); + if (strlen($user[userid]) > 15) $error = t("the username '$user[userid]' is too long: it must be less than 15 characters"); + + // Check to see whether the username or e-mail address are banned: + if ($ban = user_ban($user[userid], "username")) $error = t("the username '$user[userid]' is banned") .": $ban->reason"; + if ($ban = user_ban($user[real_email], "e-mail address")) $error = t("the e-mail address '$user[real_email]' is banned") .": $ban->reason"; + + // Verify whether username and e-mail address are unique: + if (db_num_rows(db_query("SELECT userid FROM users WHERE LOWER(userid) = LOWER('$user[userid]')")) > 0) $error = t("the username '$user[userid]' is already taken"); + if (db_num_rows(db_query("SELECT real_email FROM users WHERE LOWER(real_email) = LOWER('$user[real_email]')")) > 0) $error = t("the e-mail address '$user[real_email]' is already in use by another account"); + + return $error; +} + ?> \ No newline at end of file -- cgit v1.2.3