Change username, how?

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

hi

asp.net 3.5

I've developed a website which is using SqlMembershipProvider as
MembershipProvider. Database is a sql server 2005 database.

Now the client wants users to be able to change username on the website, how
can this be done?

(change because users are using their mobile number as username, and they
want username changed when they have a new mobile number)

any suggestions?
 
Jeff said:
asp.net 3.5

I've developed a website which is using SqlMembershipProvider as
MembershipProvider. Database is a sql server 2005 database.

Now the client wants users to be able to change username on the
website, how can this be done?

(change because users are using their mobile number as username, and
they want username changed when they have a new mobile number)

any suggestions?

Yeah, it's a pain when you want to change the "username". If you look in the
stored procedures in the aspnetdb database, you will find one named
aspnet_Membership_UpdateUser, from which I think you can glean sufficient
details to write your own SP to change UserName and LoweredUserName for the
particular UserId, ApplicationId pair corresponding to that user.

Andrew
 
Jeff said:
asp.net 3.5

I've developed a website which is using SqlMembershipProvider as
MembershipProvider. Database is a sql server 2005 database.

Now the client wants users to be able to change username on the
website, how can this be done?

(change because users are using their mobile number as username, and
they want username changed when they have a new mobile number)

any suggestions?

Yeah, it's a pain when you want to change the "username". If you look in the
stored procedures in the aspnetdb database, you will find one named
aspnet_Membership_UpdateUser, from which I think you can glean sufficient
details to write your own SP to change UserName and LoweredUserName for the
particular UserId, ApplicationId pair corresponding to that user.

Andrew
 
Below is a script I made for changing username (this is a test version, I
will add errorhandling later)., this script changes username, but after I've
changed a username I cannot login as that user. I have test user here which
I changed the username on, after username is changed I wasn't able to
login....

any ideas what I do wrong?

create procedure dbo.ah_Updateuser
@newname nvarchar(256),
@oldname nvarchar(256)
as
begin
update aspnet_Users set UserName = @newname, loweredusername = @newname
where username = @oldname;
end
 
Below is a script I made for changing username (this is a test version, I
will add errorhandling later)., this script changes username, but after I've
changed a username I cannot login as that user. I have test user here which
I changed the username on, after username is changed I wasn't able to
login....

any ideas what I do wrong?

create procedure dbo.ah_Updateuser
@newname nvarchar(256),
@oldname nvarchar(256)
as
begin
update aspnet_Users set UserName = @newname, loweredusername = @newname
where username = @oldname;
end
 
what if I create a new user with the new username, and then delete the old
user.
after new user is created use a stored procedure which set the
LastActivityDate to the LastActivityDate of the old account.
In addition I update the profile of the new user with properties from old
user.

The Profile for each user is very simple, it just holds full name, address,
and an id used in a extern system...

any pitfals I can encounter here?
 
what if I create a new user with the new username, and then delete the old
user.
after new user is created use a stored procedure which set the
LastActivityDate to the LastActivityDate of the old account.
In addition I update the profile of the new user with properties from old
user.

The Profile for each user is very simple, it just holds full name, address,
and an id used in a extern system...

any pitfals I can encounter here?
 
I'd build on the aspnet_Membership_UpdateUser SP Andrew brought to your
attention --and-- I'll remind you to save the former username as a means to
CYA.
 
I'd build on the aspnet_Membership_UpdateUser SP Andrew brought to your
attention --and-- I'll remind you to save the former username as a means to
CYA.
 
You can verify with SQL Profiler, but I'll guess the purpose of
loweredUserName is for the login verification. You said your usernames were
mobile phones, which might be all numbers, but to be safe you could use
loweredusername = LOWER(@newname).

I don't think anything prevents two users from having the same userName, so
to be safe you might want to include the applicationID in the update code,
or join to the Application table and use the loweredApplicationName.

With SQL Profiler you can see exactly what gets sent to SQL Server during
the login attempt. That will probably show you the issue right away.
 
You can verify with SQL Profiler, but I'll guess the purpose of
loweredUserName is for the login verification. You said your usernames were
mobile phones, which might be all numbers, but to be safe you could use
loweredusername = LOWER(@newname).

I don't think anything prevents two users from having the same userName, so
to be safe you might want to include the applicationID in the update code,
or join to the Application table and use the loweredApplicationName.

With SQL Profiler you can see exactly what gets sent to SQL Server during
the login attempt. That will probably show you the issue right away.
 
Back
Top