DotNetNuke – How to reset host password

DNN

I love to talk about DotNetNuke in this blog, and I’ve already did it a bunch of times (I guess). Well, I like it and I’ve been using it since the 2nd version, when it still supported MS Access databases. It was a long time ago. I will not extend myself. All you have to know about this amazing tool, you can read in the official website: http://www.dnnsoftware.com/.

Even the most experienced DotNetNuke’s users needs to handle some issues that are impossible to do, even using the administration area. Neither the SQL prompt page can help. The only way is coding, perhaps, a DotNetNuke Module. Hopefully, the ASP.NET gave to us the possibility to write “Code In Page” .aspx files and, the best part of it is, you can use all classes available in the website where it runs. So, lets use it for a very unusual trick that almost every DotNetNuke’s administrator once in their lives must needs it. Reset/redefine the host user password.

The .aspx page can be written in C# or VB.NET, it’s a matter of taste. The code bellow redefines the host password to a new one:

<!DOCTYPE html>
<%@ Page Language="C#" %>
<script runat="server">
	void Page_Load(object sender, System.EventArgs e)
	{
		DotNetNuke.Entities.Users.UserInfo user = DotNetNuke.Entities.Users.UserController.GetUserByName("host");
 
		if (user != null)
		{
			DotNetNuke.Entities.Users.UserController.ResetPasswordToken(user);
			var passwordChanged = DotNetNuke.Entities.Users.UserController.ChangePasswordByToken(user.PortalID, user.Username, "[novasenhadohost]", user.PasswordResetToken.ToString());
 
			if(passwordChanged)
			{
				Response.Write("Senha alterada com sucesso");
			}
			else
			{
				Response.Write("Não foi possível alterar a senha.");
			}
 
		}
		else
		{
			Response.Write("Usuário não encontrado");
		}
 
	}
</script>
<html lang="pt-BR">
	<head>
		<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
		<title>Redefinindo a senha do host</title>
	</head>
 
	<body>
	</body>
</html>

That is all you need. Just upload this .aspx into your DotNetNuke installation folder and runs the page in your web browser. After this, the host password will be changed to “[newhostpassword]”, or whatever you want. It saves a lot of your time.

I’ve tested this code under the versions 5, 6 and 7 of DotNetNuke .

Enjoy!