Change username, how?

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?
 
A

Andrew Morton

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
 
J

Jeff

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
 
J

Jeff

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?
 
H

Hillbilly

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.
 
P

Paul Shapiro

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top