Modx does provide a way to manually reset an administrator user password by using code that they have provided. You will need to copy the provided code into a file and then place it on your server which then allows you to add a user to the administrator user group. The following article explains how to use the code for resetting the password for a Modx admin user.
Note: The following article will be using the code editor or editor found in the Cpanel File Manager. Please see Using the Cpanel File Manager for more information.
You will need to obtain the script and manipulate it to include the user name, password and email address you want for your admin user. Once the script has the information that you will need to add the user, the next step will be to copy it on your server so that you can run it through your internet browser. The information below breaks these steps down:
Viewing the Modx API Code for Changing the Admin Password
The original code from Modx can be found here: Resetting a Password via the API. This is a copy of the code that they have provided:
<?php
define(
'MODX_API_MODE'
, true);
// Gotta set this one constant.
// Reset the password and email of an existing user
// and ensure they are a member of the specified group
$username
=
'theusername'
;
$password
=
'newpassword'
;
$email
=
'
This email address is being protected from spambots. You need JavaScript enabled to view it.
'
;
$user_group
= 1;
// 1 for Administrator
// Full path to the MODX index.php file
require_once
(
'/full/path/to/index.php'
);
// ====== Don't change anything below this line ======
if
(
empty
(
$username
) ||
empty
(
$password
) ||
empty
(
$email
)) {
die
(
'ERROR: Missing criteria.'
);
}
$modx
=
new
modX();
$modx
->initialize(
'mgr'
);
$query
=
$modx
->newQuery(
'modUser'
);
$query
->where(
array
(
'username'
=>
$username
) );
$user
=
$modx
->getObjectGraph(
'modUser'
,
'{ "Profile":{}, "UserGroupMembers":{} }'
,
$query
);
// print_r($user); exit;
if
(!
$user
) {
die
(
"ERROR: No user with username $username"
);
}
$user
->set(
'username'
,
$username
);
$user
->set(
'active'
,1);
$user
->set(
'password'
,
$password
);
$user
->Profile->set(
'email'
,
$email
);
$user
->Profile->set(
'blocked'
, 0);
$user
->Profile->set(
'blockeduntil'
, 0);
$user
->Profile->set(
'blockedafter'
, 0);
// Verify the user is a member of specified User Group
$is_member
= false;
if
(!
empty
(
$user
->UserGroupMembers)) {
foreach
(
$user
->UserGroupMembers
as
$UserGroupMembers
) {
if
(
$UserGroupMembers
->get(
'user_group'
) ==
$user_group
) {
$is_member
= true;
break
;
}
}
}
// Add the User to the User Group if he is not a member
if
(!
$is_member
) {
// Verify the user group exists
$UserGroup
=
$modx
->getObject(
'modUserGroup'
,
$user_group
);
if
(!
$UserGroup
) {
die
(
"ERROR: User Group $user_group does not exist."
);
}
$Member
=
$modx
->newObject(
'modUserGroupMember'
);
$Member
->set(
'user_group'
,
$user_group
);
$Member
->set(
'member'
,
$user
->get(
'id'
));
// Super User = role 2
$Member
->set(
'role'
, 2);
$Member
->set(
'rank'
, 0);
$user
->addOne(
$Member
,
'UserGroupMembers'
);
}
/* save user */
if
(!
$user
->save()) {
die
(
'ERROR: Could not save user.'
);
}
print
"SUCCESS: User $username updated."
;
?>
Using Cpanel to Create API File and Edit the Code
Final Step - Execute the File and then Secure It from Further Use
You should be very careful when using this script as it an obvious way to bypass your security and gain access to the data of your site. Use of this file should be limited to Administrators of the MODX installation. It is recommended that the file used to add the administrator user would be best used and then removed from the server for purposes of keeping your site secure.
Email: | support@WebHostingHub.com | Ticket: | Submit a Support Ticket |
---|---|---|---|
Call: |
877-595-4HUB (4482) 757-416-6627 (Intl.) |
Chat: | Click To Chat Now |
We value your feedback!
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
new! - Enter your name and email address above and we will post your feedback in the comments on this page!