The standard profile page doesn't allow users to change their username, only their e-mail, display name etc.
I have imported a large number of user accounts into DNN from a previous application, and the imported users have their usernames set to be the same as their e-mail address (because thats how they used to log onto the old application)
I wanted a way for these users to be able to change their usernames if they wanted to, and I have written a simple module that I can drop onto a page beside the user accounts module that will allow them to do that.
Before I implement this, I wanted to check whether anyone knew of any good reason not to do it.
It seems like such a simple thing to do that I thought there must be some good reason why the ability to change username was not included in the framework as standard.
Will I encounter some horrible database corruption somewhere down the line if I allow changing of usernames?
Thanks
Steve
PS.
The module I have written simply makes a call to the following stored procedure to do the change, passing in the old and new username as parameters.
CREATE PROCEDURE ChangeUsername
@oldName nvarchar(128),
@newName nvarchar(128)
AS
declare @error_var int, @rowcount_var int
declare @newNameCount int
begin transaction
select @newNameCount = count(*)
from Users
where Username = @newName
if @newNameCount > 0
begin
RAISERROR('Username already exists. @newName=%s', 10, 1, @newName)
ROLLBACK TRANSACTION
RETURN
end
update Users
set Username = @newName
where Username = @oldName
SELECT @error_var = @@ERROR, @rowcount_var = @@ROWCOUNT
IF @rowcount_var <> 1 OR @error_var <> 0
BEGIN
RAISERROR('Could not Update User.Username. @oldName=%s', 10, 1, @oldName)
ROLLBACK TRANSACTION
RETURN
END
update aspnet_Users
set
Username = @newName,
LoweredUserName = LOWER(@newName)
where LoweredUserName = LOWER(@oldName)
SELECT @error_var = @@ERROR, @rowcount_var = @@ROWCOUNT
IF @rowcount_var <> 1 OR @error_var <> 0
BEGIN
RAISERROR('Could not Update aspnet_Users.Username. @oldName=%s', 10, 1, @oldName)
ROLLBACK TRANSACTION
RETURN
END
Commit transaction
GO