Modifying Username

Author Message

Trevor Clowry

Wednesday 23 November 2005 4:59:43 am

Does anyone know a way to change a user's username after it has been created. The username box gets disabled after the user is created.
Thanks!

Gurudutt Verma

Thursday 24 November 2005 1:00:39 am

Hi Trevor Clowry

Why you want to change the username ? If it is require to change that better to create new user instead.

Trevor Clowry

Thursday 24 November 2005 1:44:27 am

Thanks Gurudutt for the reply.

The name of the company that owns the website previously was called RYT, so i had made all the usernames like RYT001, RYT002 etc.
However recently they have changed the company name to NAA and was wondering if they could change the usernames to NAA001, NAA002. Since there are over 200 members, I dont want to manually create all the users again.

Gurudutt Verma

Thursday 24 November 2005 2:59:51 am

Hi Trevor Clowry

This is not supported by eZ publish.

This is nice requirement, I guess it might be put in suggestion.

I haven't tried this, but some kind of script can be created to change that in database, but you have to be very careful and need to take backup of your database first before executing such script.

Of cource if you create such script, don't forget to clear all ezsessions before executing this.

Łukasz Serwatka

Thursday 24 November 2005 3:10:03 am

Changing user names will cause some problems:

User passwords are generated by default from username and password.

md5( "user\npassword" );

All users logins are in ezuser table. You will have to update user passwords as well if you change logins.

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Clemens T

Thursday 24 November 2005 3:10:08 am

Ofcourse keep the post of Gurudutt in mind, but here's how I let users edit themselves (even their username):

...
			$eztmpuser = eZUser::fetch( $userid );	
			if(is_object($contentObject) && is_object($eztmpuser)){
				$eztmpuser->setAttribute( 'login', $http->postVariable('email') );
				$eztmpuser->setAttribute( 'email', $http->postVariable('email') );
				$eztmpuser->store();

...

ofCourse you can make a for loop etc..
but you need to know how programming with ezpublish works (the php side of it) to complete this.

BACKUP.. before you start :)

Clemens T

Thursday 24 November 2005 3:12:26 am

Lukasz,
this seems untrue,

because if I execute the code I just provided, it is still possible to log-in with the old password!

(so.. once generated.. the hash still means the same (is my first guess)).

Greets,
Clemens

Łukasz Serwatka

Thursday 24 November 2005 3:17:51 am

Yes, but go to database and change it there, then login in to the system is impossible ;)

Of course using script to change logins is good way.

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Clemens T

Thursday 24 November 2005 3:22:14 am

hahaha, cool comment.

Always use the data-access layer when changing data is my philosophy...

So, that's why I provided the essence of the login-change-code :).

Greets,
Clemens

Łukasz Serwatka

Thursday 24 November 2005 3:25:43 am

Yeah, I think Trevor will be happy with your code ;)

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Trevor Clowry

Thursday 24 November 2005 4:19:35 am

Thanks guys for the feedback.

Since I know all the old username and password combinations. I have wrote a php script to:

1. Rename all the the logins(in login column of ezuser table) from RYT001 to NAA001 etc
2. Create a new md5 password hash for each user based on the new login and old password.
3. Added the new logins and passwords to the database through the mysql command line.
4. It works!
So know i have new logins with the same passwords.

Thanks a million Clemens and Lukasz. I really appreciate the feedback.

Gurudutt Verma

Thursday 24 November 2005 4:56:00 am

Hi Trevor Clowry

This was really great discussion and congratulations as you got the solution.

btw it is suggested to not use mysql prompt to change stuffs in table use code as suggested by Clemens Timmermans insted that's better and much safe but you got your solution that's great.

Clemens T

Thursday 24 November 2005 5:19:37 am

Ok, good to hear it has been fixed!

Trevor Clowry

Thursday 24 November 2005 5:53:43 am

Yep, its working perfectly.

Thanks Gurudutt too!

Gurudutt Verma

Thursday 24 November 2005 6:03:37 am

Hi Trevor

Thanks,

may be you can share your code here so it could be useful for others :-)

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 16:02:55
Script start
Timing: Jan 18 2025 16:02:55
Module start 'layout'
Timing: Jan 18 2025 16:02:55
Module start 'content'
Timing: Jan 18 2025 16:02:56
Module end 'content'
Timing: Jan 18 2025 16:02:56
Script end

Main resources:

Total runtime1.2577 sec
Peak memory usage4,096.0000 KB
Database Queries97

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0048 588.9297152.6094
Module start 'layout' 0.00480.0086 741.539139.4297
Module start 'content' 0.01341.2428 780.9688747.2891
Module end 'content' 1.25620.0014 1,528.257828.1875
Script end 1.2577  1,556.4453 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00310.2429160.0002
Check MTime0.00130.1031160.0001
Mysql Total
Database connection0.00070.055610.0007
Mysqli_queries1.158992.1442970.0119
Looping result0.00080.0664950.0000
Template Total1.221597.120.6108
Template load0.00200.160820.0010
Template processing1.219596.962520.6098
Template load and register function0.00020.012010.0002
states
state_id_array0.00090.074110.0009
state_identifier_array0.00130.106320.0007
Override
Cache load0.00190.1513760.0000
Sytem overhead
Fetch class attribute can translate value0.00060.045440.0001
Fetch class attribute name0.00120.0941170.0001
XML
Image XML parsing0.00140.111540.0004
class_abstraction
Instantiating content class attribute0.00000.0036220.0000
General
dbfile0.00100.0757240.0000
String conversion0.00000.000740.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
15content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
7content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
20content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
7content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 52
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs