Page 1 of 2

Edit user name

Posted: Tue Feb 25, 2003 12:51 am
by Pagemakers Design
I would like the facility to edit a username from say JOHN SMITH or john smith to John Smith.

Currently this can't be done and the following error is generated "Sorry, but this username has already been taken." when the user management page is submitted in the CP.

Cool

Posted: Tue Feb 25, 2003 1:19 am
by JSLover
Cool I'd like this too...like AIM reformat username...as long as you use the same chars in the same order it will let you change case...this should be easy...I'd like to do it. I'm assuming you want the user to be able to change case even when the admin option Allow username changes is NOT on. So if they can't change usernames without admin help they CAN change there current usernames case. I think you were also saying that it gives you an error that the names are the same...I will try to correct that too, obviously. "...when the user management page is submitted in the CP."...even the admin can't change case? Workaround...
JOHN SMITH -> John Smithx
John Smithx -> John Smith
...in the ACP that is. Users could only do this if Allow username changes is on in the ACP. What version? In mine changing case in Profile don't work & don't give an error, same for my profile here, don't work but no error either. Changing case in ACP works in my version without error.

Posted: Tue Feb 25, 2003 1:24 am
by Pagemakers Design
Yup, I would like to use this as an admin feature with the change usernames option off.

I see your workaround but there must be a better way!

Another option would be to force the name to display as "John Smith", no matter how it appears in the database......

what version?

Posted: Tue Feb 25, 2003 5:42 am
by JSLover
Pagemakers Design wrote: Yup, I would like to use this as an admin feature with the change usernames option off.

What version do you have? My version works via ACP. I'm going to make the mod for users to be able to reformat their case. But in the ACP it already works.

Posted: Tue Feb 25, 2003 9:07 am
by Pagemakers Design
I have 2.04

If I change john smith to John Smith in the CP it won't let me saying the username already exists.

almost got it

Posted: Tue Feb 25, 2003 2:20 pm
by JSLover
I've almost got it...I got it to where the user can do it but I'm having trouble with the admin being able to do it...I need help with this part...(for any mod writers out there)...
  • In includes/functions_validate.php...

    $sql = "SELECT username
    FROM " . USERS_TABLE . "
    WHERE LOWER(username) = '" . strtolower($username) . "'";
    if ( $result = $db->sql_query($sql) )
    {
    if ( $row = $db->sql_fetchrow($result) )
    {
    if ( ( $userdata['session_logged_in'] && $row['username'] != $userdata['username'] ) || !$userdata['session_logged_in'] )
    {
    return array('error' => true, 'error_msg' => $lang['Username_taken']);
    }
    }
    }
...is this preventing an admin from renaming someone to an already existing name? This is what I have...& it works but it might open up renaming to an existing user...
  • $sql = "SELECT username
    FROM " . USERS_TABLE . "
    WHERE LOWER(username) = '" . strtolower($username) . "'";
    if ( $result = $db->sql_query($sql) )
    {
    if ( $row = $db->sql_fetchrow($result) )
    {
    if ( ( $userdata['session_logged_in'] && ($row['username'] != $userdata['username'] && preg_match("/^" . preg_replace('/ /', '', $username=preg_replace("/ +/", ' ', $username)) . "$/i", preg_replace('/ /', '', $userdata['username']))) ) || !$userdata['session_logged_in'] )
    {
    return array('error' => true, 'error_msg' => $lang['Username_taken']);
    }
    }
    }
...1st I tried && !preg_match( to get the meaning "if they don't match in this way then give the error" but that got the opposite so I removed the ! & it works...just I don't know the side effects. Anyone have a check that'll safely do...
  • if (My Name == myname) //returning true...in a way that forgives case & spacing...like my regexs
...but not do...
  • if (My Name == Someone Elses Name) //returning true...not do this
...so it needs to allow a) the admin changing the name to anything that's not an existing name or b) changing it to an existing username but which is the same username with different case/spacing.

Posted: Tue Feb 25, 2003 2:29 pm
by sj26
instead of the long winded

Code: Select all

if ( ( $userdata['session_logged_in'] && ($row['username'] != $userdata['username'] && preg_match("/^" . preg_replace('/ /', '', $username=preg_replace("/ +/", ' ', $username)) . "$/i", preg_replace('/ /', '', $userdata['username']))) ) || !$userdata['session_logged_in'] )
why not use the simpler

Code: Select all

if ( ( $userdata['session_logged_in'] && strcasecmp($row['username'], $userdata['username']) ) || !$userdata['session_logged_in'] )
Using the case-insensitive strcasecmp function built into php? This returns 0 when the strings are the same (case insensitivly)...

May I also suggest that in Admin instead of 'Allow name changes' and 'none' have a middle option like 'allow changing of username case'...

Posted: Tue Feb 25, 2003 2:45 pm
by Pagemakers Design
For my purposes I don't want users to be able to do this, just the admin.

I lookk forward to the completed job.

Posted: Wed Feb 26, 2003 12:03 am
by Pagemakers Design
Can it be done?

lets dissect it

Posted: Wed Feb 26, 2003 5:26 am
by JSLover
sj26 wrote: instead of the long winded

Yours don't do what my "long winded" version does...lets dissect...
  • if ( ( $userdata['session_logged_in'] && ($row['username'] != $userdata['username'] &&

    ...standard what it already does...

    preg_match("/^" .

    ...this matches (for clarity) $whattheytypedin with $whatsinthedatabase...but...

    preg_replace('/ /', '',

    ...remove spaces for comparison...

    $username=preg_replace("/ +/", ' ', $username)

    ...limit to one sequential space (no John<s><s><s>Doe {<s> = space}) & save back to $username...unlike remove all spaces which only removes spaces for comparison...this limits them to one & saves it...

    )

    ...finish preg_replace...removing spaces...

    . "$/i",

    ...continue preg_match...matching case-insensitively...

    preg_replace('/ /', '', $userdata['username'])

    ...what to compare to (the $whatsinthedatabase)...again removing spaces for comparison...

    )) ) || !$userdata['session_logged_in'] )

    ...finishing everything...
sj26 wrote: why not use the simpler
  • if ( ( $userdata['session_logged_in'] &&

    ...standard what it already does...

    strcasecmp($row['username'], $userdata['username'])

    ...match case-insensitively...not ignoring spaces...not limiting to one space...

    ) || !$userdata['session_logged_in'] )

    ...finishing everything...
sj26 wrote: Using the case-insensitive strcasecmp function built into php? This returns 0 when the strings are the same (case insensitivly)...

May I also suggest that in Admin instead of 'Allow name changes' and 'none' have a middle option like 'allow changing of username case'...


I thought about this but a) I don't know how to add to the admin panel without it being hard or messing something up. b) I don't see why admins care if someone changes case but if it's really an issue I can think of something...any one willing to write the part that adds the option to the admin panel...please do. I'll look into doing it myself but if I have to mess with the database I'm screwed...if I only need to add another possible value for (some variable like) $board['allow_username_changes']...I could but then other things relying on only 2 options will mess up. If someone wants to make $board['allow_username_case_changes'] then great (this variable is only an example...it should be like whatever the real $board['allow_username_changes'] is...like maybe it's...$board_config['allow_username_changes'] or something then this should be $board_config['allow_username_case_changes']

Re: lets dissect it

Posted: Wed Feb 26, 2003 9:10 am
by sj26
I'm am deeply sorry... I was slack... tired and it was late. I did not read your code properly. It is a good method. if you like I can help you out with the admin bit.

getting closer

Posted: Wed Feb 26, 2003 2:39 pm
by JSLover
Getting closer...I just setup a new install of phpbb & added my mod via my mod instructions & tested it & it did what I thought...it let you rename people to the same name...but it didn't have the effect I thought it would...I thought it would collide in the db & corrupt it (that's why I fresh installed so I could get a different db prefix)...or at least corrupt the users even if you could delete just the users involved & be ok...but it didn't do either...it just let you have 2 people with the same username & still be able to rename them back. I've fixed it since then...now I've got a version that lets the admin do it without being able to collide with an existing nick & still be able to rename to the same nick with a different case. & the user can still reformat their name also. Now I just need config options to disable users reformatting their name...but I must ask you (anyone reading this) to consider why you care if they change their case...my mod limits them from renaming themselves anything more than case & spacing...

Valid examples...
john doe can become...
  • John Doe
    johndoe
    JohnDoe
    J o h n Doe
    JOHNDOE
    JOHN DOE
Invalid examples...
but cannot become (<s> = space {otherwise you couldn't tell the difference in the example})...
  • john<s><s><s>doe
    doe john
    jane doe
    john doe2
...the 1st example shows that my mod limits spaces to one sequential space...note you don't get an error when you try...but when you go back you'll notice that any amount of spaces are now one.
sj26 wrote: if you like I can help you out with the admin bit.

Ok...do you mean adding the option to the admin panel? Cuz now I got it mostly working. If you do mean an admin panel option could you also add a variable I could check to fulfill his other request...
Pagemakers Design wrote: Another option would be to force the name to display as "John Smith", no matter how it appears in the database......

...my implementation is really going to control what's in the database too but that's just because I think it'd be easier. I must ask you tho, Pagemakers Design, do you mind if I implement this as...
if the username has any spaces in it then make it proper case
otherwise leave it alone
...this would mean...
JOHN SMITH would become John Smith
...but...
JSLover would stay JSLover instead of becoming Jslover
...I know I wouldn't want my name to be capped that way. Another option would be...
if the username has any spaces & is all lowercase or all uppercase then make it proper case
otherwise leave it alone
...then this would mean...
JOHN SMITH would still become John Smith
john smith would still become John Smith
...but...
JOhn smith would stay JOhn smith
John sMith would stay John sMith
primedomain would stay primedomain
...this would be best cuz it gets lazy people who have caps on or off but leaves people alone that cap it like they want it...or only have one word instead of it being 2 or more words like a real name.

Posted: Wed Feb 26, 2003 2:59 pm
by Pagemakers Design
This allows admin users of ver 2.04 to change usernames from say john smith to John Smith etc:



## EasyMod 0.0.7 compliant
##############################################################
## Mod Title: Username Edit Fix
## Mod Version: 1.0.0
## Mod Description: This fixes an issue that prevents
## admins from changing the case of
## usernames.
##
## Installation Level: easy
## Installation Time: 2-5 Minutes
## Files To Edit: admin/admin_users.php
## includes/functions_validate.php
## Includes Files: n/a
##############################################################
## For Security Purposes, Please Check: http://www.phpbb.com/mods/downloads/ for the
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code
## to enter into your phpBB Forum. As such, phpBB will not offer support for MOD's not offered
## in our MOD-Database, located at: http://www.phpbb.com/mods/downloads/
##############################################################
## Author Notes:
##
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##############################################################

#
#-----[ OPEN ]------------------------------------------
#
admin/admin_users.php


#
#-----[ FIND ]------------------------------------------
#
$result = validate_username($username);


#
#-----[ REPLACE ]------------------------------------------
#
$result = validate_username($username, $user_id);


#
#-----[ OPEN ]------------------------------------------
#
includes/functions_validate.php

#
#-----[ FIND ]------------------------------------------
#
function validate_username($username)


#
#-----[ REPLACE ]------------------------------------------
#
function validate_username($username, $user_id = '')

#
#-----[ FIND ]------------------------------------------
#
WHERE LOWER(username) = '" . strtolower($username) . "'";

#
#-----[ REPLACE ]------------------------------------------
#
WHERE LOWER(username) = '" . strtolower($username) . "' AND user_id != '$user_id'";


#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM

why?

Posted: Wed Feb 26, 2003 4:01 pm
by JSLover
Why write your own requested mod? Also please fix the horiz scrolling.

Posted: Wed Feb 26, 2003 4:03 pm
by Pagemakers Design
I didn't write it. Someone kindly sent it to me last night.