I believe what the topic started meant, was a means to always render a
display name (screen name) on the boards, and use the login name
only for logging onto the boards. The display name can be the real name or any other handle a member uses on the Net.
I bet this will be
much simpler to implement than hunting for all occurrences of
user name and replacing them with something else. The problem is: how?
I think a solution is to modify the
user table and add a
displayname column and an unique index on this column. The vBulletin authentication and access control code would then the only consumer of the
username field.
FWIW I also came across the
vBulletin 2/3 hack to display a profile field instead of the user name. However the hack cannot readily be applied on vBulletin 4 since I believe the template engine changed in vBulletin 4 (the variable names and the syntax are different).
--------------- Added [DATE]1283720093[/DATE] at [TIME]1283720093[/TIME] ---------------
I made it work on vBulletin 4.0.6. This patch basically authenticates the
login name instead of the
user name. It requires adding one column to the user table and an edit of a core vBulletin file. Hence the following warning:
WARNING: DO NOT ATTEMPT THE FOLLOWING IF YOU ARE NOT ACQUAINTED WITH SQL AND PHP.
Step 1: add an indexed
loginname column to the
user table and to the
strikes table:
ALTER TABLE user ADD loginname varchar(100) NOT NULL DEFAULT '';
CREATE INDEX loginname ON user(loginname);
ALTER TABLE strikes ADD loginname varchar(100) NOT NULL DEFAULT '';
CREATE INDEX loginname ON strikes(loginname);
The index is needed for performance reasons.
Step 2: set the
loginname value for all users to the current
username value:
UPDATE user SET loginname = username;
Step 3: set the
username for
one test user you can log on with to the display name. In my case, the display name is stored as
field5 in the
userfield table. Updating only the user name from a
test user with user ID = 1234 can be done
in my case with the following SQL query:
UPDATE user SET username = (SELECT field5 from userfield where userid = 1234) where userid = 1234;
Step 4: go to your webserver and locate the file "
includes/functions_login.php".
4.1. Copy that file to functions_login.php.orig so you can revert your edit should something go wrong
4.2. Apply the following patch to functions_login.php:
Code:
--- functions_login.php.orig Mon Aug 30 15:37:07 2010
+++ functions_login.php Thu Sep 9 18:12:35 2010
@@ -93,16 +93,18 @@
if (!empty($username))
{
+ // FYI - the 'strikes' table records strikes for a given username,
+ // hence we add a 'loginname' column to the 'strikes' table.
$strikes_user = $vbulletin->db->query_first("
SELECT COUNT(*) AS strikes
FROM " . TABLE_PREFIX . "strikes
WHERE strikeip = '" . $vbulletin->db->escape_string(IPADDRESS) . "'
- AND username = '" . $vbulletin->db->escape_string(htmlspecialchars_uni($username)) . "'
+ AND loginname = '" . $vbulletin->db->escape_string(htmlspecialchars_uni($loginname)) . "'
");
if ($strikes_user['strikes'] == 4) // We're about to add the 5th Strike for a user
{
- if ($user = $vbulletin->db->query_first("SELECT userid, username, email, languageid FROM " . TABLE_PREFIX . "user WHERE username = '" . $vbulletin->db->escape_string($username) . "' AND usergroupid <> 3"))
+ if ($user = $vbulletin->db->query_first("SELECT userid, username, email, languageid FROM " . TABLE_PREFIX . "user WHERE loginname = '" . $vbulletin->db->escape_string($loginname) . "' AND usergroupid <> 3"))
{
$ip = IPADDRESS;
eval(fetch_email_phrases('accountlocked', $user['languageid']));
@@ -114,9 +116,9 @@
/*insert query*/
$vbulletin->db->query_write("
INSERT INTO " . TABLE_PREFIX . "strikes
- (striketime, strikeip, username)
+ (striketime, strikeip, username, loginname)
VALUES
- (" . TIMENOW . ", '" . $vbulletin->db->escape_string(IPADDRESS) . "', '" . $vbulletin->db->escape_string(htmlspecialchars_uni($username)) . "')
+ (" . TIMENOW . ", '" . $vbulletin->db->escape_string(IPADDRESS) . "', '" . $vbulletin->db->escape_string(htmlspecialchars_uni($username)) . "', '" . $vbulletin->db->escape_string(htmlspecialchars_uni($loginname)) . "')
");
$strikes++;
@@ -128,7 +130,7 @@
{
global $vbulletin;
- $vbulletin->db->query_write("DELETE FROM " . TABLE_PREFIX . "strikes WHERE strikeip = '" . $vbulletin->db->escape_string(IPADDRESS) . "' AND username='" . $vbulletin->db->escape_string(htmlspecialchars_uni($username)) . "'");
+ $vbulletin->db->query_write("DELETE FROM " . TABLE_PREFIX . "strikes WHERE strikeip = '" . $vbulletin->db->escape_string(IPADDRESS) . "' AND loginname='" . $vbulletin->db->escape_string(htmlspecialchars_uni($loginname)) . "'");
}
// ###################### Start set_authentication_cookies #######################
@@ -157,7 +159,7 @@
global $vbulletin;
$username = strip_blank_ascii($username, ' ');
- if ($vbulletin->userinfo = $vbulletin->db->query_first("SELECT userid, usergroupid, membergroupids, infractiongroupids, username, password, salt FROM " . TABLE_PREFIX . "user WHERE username = '" . $vbulletin->db->escape_string(htmlspecialchars_uni($username)) . "'"))
+ if ($vbulletin->userinfo = $vbulletin->db->query_first("SELECT userid, usergroupid, membergroupids, infractiongroupids, username, password, salt FROM " . TABLE_PREFIX . "user WHERE loginname = '" . $vbulletin->db->escape_string(htmlspecialchars_uni($username)) . "'"))
{
if (
$vbulletin->userinfo['password'] != iif($password AND !$md5password, md5(md5($password) . $vbulletin->userinfo['salt']), '') AND
Step 5: Login with this test user to verify you can still log onto the vBulletin platform.
Step 6: Go to the
Admin CP > Maintenance > Rebuild thread information and then run
Rebuild forum information to update the user name in threads. This may take a while on bigger boards.
I have checked with a regular user and a moderator on the boards with this hack in place. It works for both (the user can post, and the moderator can moderate the threads).
Please note that I still have to more thoroughly check all vBulletin functionality with this hack in place. Review from more experienced vBulletin developers/coders is appreciated!
I hope it is OK to post this hack here. Who knows it might get into the vBulletin code base?