DotNetNuke – How to reset host password


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:

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)
			var passwordChanged = DotNetNuke.Entities.Users.UserController.ChangePasswordByToken(user.PortalID, user.Username, "[novasenhadohost]", user.PasswordResetToken.ToString());
				Response.Write("Senha alterada com sucesso");
				Response.Write("Não foi possível alterar a senha.");
			Response.Write("Usuário não encontrado");
<html lang="pt-BR">
		<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
		<title>Redefinindo a senha do host</title>

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 .