Jump to content

Reset Admin Password or Add SuperUser Rol


Ross
 Share

Recommended Posts

Hi! We have the ProcessWire 2.3.1 version

The old webmaster don't give us the logindetails.

Is it possible to add the superuser role to a user with content-manager role through lines of code in php?

We do not know the username and the administrator password but we have access to the hosting through cpanel, phpmyadmin and public html files.

What do you recommend? 

How could we reset the admin password or how could we assign a superuser role to a content-manager user?

Thank you

Ross

Link to comment
Share on other sites

Behind the scenes, the admin user is a page with the id 41, so you can determine the username by running the following sql query:

select `name` from `pages` where `id` = 41;

The quickest way to reset the password should be this:

 

  • Like 2
Link to comment
Share on other sites

On 10/1/2021 at 7:03 AM, bernhard said:

My  has a snippet for that, that you can simply paste in site/ready.php:

$admin = $users->get(41);
$admin->setAndSave('pass', '');
$admin->setAndSave('name', '');
die("admin url = {$pages->get(2)->httpUrl}, admin username = {$admin->name}");

8BylgUT.gif

Thank You Bernhard! Your VSCode snippets extension serve only to reset the administrator password or does
it also serve to add a new super user through code?

Sorry for the questions, I'm a newbie.

 

Link to comment
Share on other sites

18 hours ago, bernhard said:

Just reset the name + password for the superuser, then you can login as that user and create other users or edit them and their roles.

We have the ProcessWire 2.3.1 version and only have the config.php file inside the site folder.

Do I copy and paste the code in that file?

image.png.f5e6c2660435c65c5a1bfa3627cc07b2.png

Thank You Bernhard! 

Link to comment
Share on other sites

2 hours ago, Ross said:

We have the ProcessWire 2.3.1 version and only have the config.php file inside the site folder.

Do I copy and paste the code in that file?

That's quite an old version of ProcessWire. ready.php and the likes were introduced in ProcessWire 2.6.7, so you cannot use ready.php in your version. You can still use the API to change your password. You will need to add the code to a template file. Pick one template file from your /site/templates folder, edit it, and add the following code. The steps are:

  1. Pick a template file.
  2. Open it for editing. Depending on your server, you might have to download it to edit it locally the upload the edited version.
  3. Add the code below. The code needs to be added within php code blocks within that template file. Do not delete your templates existing code.
  4. Visit a page on your website (frontend) that uses that template file (e.g. an about page that uses a template called basic-page, etc).
  5. Your password (and optionally user name) will be changed.
  6. Edit the template file in #1 and #2 above.
  7. Remove the password change code.
  8. Reupload the edited template file if it was edited locally.
  9. Go to your admin URL and login with your new password (and new name if you changed it as well).

PHP code

<?php

namespace ProcessWire;
#### DON'T ADD ABOVE TO YOUR TEMPLATE FILE. IT IS JUST FOR SYNTAX HIGHLIGHTING HERE #### 

################# COPY CODE STARTS HERE #################

// get the default ProcessWire admin superuser
$admin = $users->get(41);
// turn output formatting off
$admin->of(false);
// change the password
$admin->pass = "YOUR_VERY_STRONG_PASSWORD_HERE";
  // change the user name (optional: comment out code if you know and want to use the existing user name)
$admin->name = "YOUR_USER_NAME_HERE";
// SAVE YOUR CHANGES
$admin->save();  
  
  ################# COPY CODE END HERE #################

 

Edited by kongondo
  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...
On 10/6/2021 at 2:31 AM, kongondo said:

That's quite an old version of ProcessWire. ready.php and the likes were introduced in ProcessWire 2.6.7, so you cannot use ready.php in your version. You can still use the API to change your password. You will need to add the code to a template file. Pick one template file from your /site/templates folder, edit it, and add the following code. The steps are:

  1. Pick a template file.
  2. Open it for editing. Depending on your server, you might have to download it to edit it locally the upload the edited version.
  3. Add the code below. The code needs to be added within php code blocks within that template file. Do not delete your templates existing code.
  4. Visit a page on your website (frontend) that uses that template file (e.g. an about page that uses a template called basic-page, etc).
  5. Your password (and optionally user name) will be changed.
  6. Edit the template file in #1 and #2 above.
  7. Remove the password change code.
  8. Reupload the edited template file if it was edited locally.
  9. Go to your admin URL and login with your new password (and new name if you changed it as well).

PHP code

<?php

namespace ProcessWire;
#### DON'T ADD ABOVE TO YOUR TEMPLATE FILE. IT IS JUST FOR SYNTAX HIGHLIGHTING HERE #### 

################# COPY CODE STARTS HERE #################

// get the default ProcessWire admin superuser
$admin = $users->get(41);
// turn output formatting off
$admin->of(false);
// change the password
$admin->pass = "YOUR_VERY_STRONG_PASSWORD_HERE";
  // change the user name (optional: comment out code if you know and want to use the existing user name)
$admin->name = "YOUR_USER_NAME_HERE";
// SAVE YOUR CHANGES
$admin->save();  
  
  ################# COPY CODE END HERE #################

 

Hi! Thanks for helping. I'm going to try your steps.

For example

  1. Pick a template file.
    image.png.6d4c90a6f9a3bbee6ff447adc134d4fd.png
  2. Open it for editing.
    image.png.045799e8680c28780a27a53f4ab5d342.png 
  3. Add the code below. The code needs to be added within php code blocks within that template file. Do not delete your templates existing code.
    image.png.931e2e81c66a35a2b7cc8b816b985244.png
     
  4. Visit a page on your website (frontend) that uses that template file (e.g. an about page that uses a template called basic-page, etc).
    www.mysite.com/basic-page.php
     
  5. Your password (and optionally user name) will be changed.
  6. Edit the template file in #1 and #2 above.
  7. Remove the password change code.
  8. Reupload the edited template file if it was edited locally.
  9. Go to your admin URL and login with your new password (and new name if you changed it as well).
    www.mysite.com/processwire/

Before, I'm going to make a backup of files and database, right?

Thank you so much for help me!

Link to comment
Share on other sites

1 hour ago, Ross said:

Visit a page on your website (frontend) that uses that template file (e.g. an about page that uses a template called basic-page, etc).
www.mysite.com/basic-page.php

That is probably not a valid ProcessWire page. ProcessWire does not output page URLs with .php extensions. A frontend page would be something like www.mysite.com/about-us/ or www.mysite.com/services/. In case you don't know which pages use which templates, find out if you have a template file called home.php and use that instead of basic-page.php. In that case, you would then have to visit www.mysite.com for the code to run.

1 hour ago, Ross said:

Before, I'm going to make a backup of files and database, right?

Yes, it's always good to make a backup of the database. In this case a backup of the files is not  strictly necessary but it does no harm if you do.

1 hour ago, Ross said:

Thank you so much for help me!

Let us know how it goes 🙂.

Link to comment
Share on other sites

On 10/15/2021 at 12:51 AM, kongondo said:

That is probably not a valid ProcessWire page. ProcessWire does not output page URLs with .php extensions. A frontend page would be something like www.mysite.com/about-us/ or www.mysite.com/services/. In case you don't know which pages use which templates, find out if you have a template file called home.php and use that instead of basic-page.php. In that case, you would then have to visit www.mysite.com for the code to run.

Yes, it's always good to make a backup of the database. In this case a backup of the files is not  strictly necessary but it does no harm if you do.

Let us know how it goes 🙂.

I have tested and it worked perfectly!

I am very grateful for the help! 

Ross 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...