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
  • Thanks 1
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

  • 4 months later...
On 10/1/2021 at 12:03 PM, bernhard said:

My VSCode snippets extension 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

@bernhard thank you very much this solution worked perfectly!

Link to comment
Share on other sites

  • 5 months later...
On 10/1/2021 at 12:03 PM, bernhard said:

My VSCode snippets extension 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

I did this and my site gave an internal error (500), I removed it and it got back to working order.

I also tried the following code in /site/templates/home.php and got no internal errors, but I still can't access as an admin user.

$u = $users->get('admin'); // or whatever your username is
$u->of(false); 
$u->pass = 'anypassword';
$u->save();

Thanks in advance!

Link to comment
Share on other sites

On 10/1/2021 at 12:03 PM, bernhard said:

My VSCode snippets extension 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

Thanks for getting back, I think I have the user here in pages:
name: new_su
modified_users_id: 41

I did the changes on that user inside home.php, but I still can't enter with those details.

Link to comment
Share on other sites

Quote

2022-08-31 13:23:28    guest   https://jaknetz.net/  Fatal Error:  Uncaught Error: Call to a member function numChildren() on null in /home/sdt9pp9twqkd/public_html/websitedomain.com/wire/core/PagesEditor.php:345 Stack trace: #0 /home/sdt9pp9twqkd/public_html/websitedomain.com/wire/core/Pages.php(1185): ProcessWire\PagesEditor->setupNew(Object(ProcessWire\NullPage)) #1 /home/sdt9pp9twqkd/public_html/websitedomain.com/wire/core/Wire.php(417): ProcessWire\Pages->___setupNew(Object(ProcessWire\NullPage)) #2 /home/sdt9pp9twqkd/public_html/websitedomain.com/wire/core/WireHooks.php(951): ProcessWire\Wire->_callMethod('___setupNew', Array) #3 /home/sdt9pp9twqkd/public_html/websitedomain.com/wire/core/Wire.php(485): ProcessWire\WireHooks->runHooks(Object(ProcessWire\Pages), 'setupNew', Array) #4 /home/sdt9pp9twqkd/public_html/websitedomain.com/wire/core/PagesEditor.php(435): ProcessWire\Wire->__call('setupNew', Array) #5 /home/sdt9pp9twqkd/public_html/websitedomain.com/wire/core/Pages.php(799): ProcessWire\PagesEditor->save(Object(ProcessWire\NullPage), Array) #6 /home/sdt9pp9twqkd/public_html/websitedomain.com/wi (line 345 of /home/sdt9pp9twqkd/public_html/websitedomain.com/wire/core/PagesEditor.php)

Does this shed any light on my issues?
Thanks once again for you help.

Link to comment
Share on other sites

It seems you are trying to save a NullPage. Your $pages->get(41) will return a NullPage if no page with ID 41 exists. So a setAndSave() will fail. If you set $config->debug = true in your config.php you should maybe get errors displayed instead of a non-saying error 500.

You can only reset passwords of a user that exists. So your first challenge is to get the name or id of the superuser. You can also inspect the DB table "pages" if you have access to your DB

Users have templates_id=3

A727KBn.png

Link to comment
Share on other sites

  • 1 year later...

Hi all

I'm having a similar issue as @janaro.

I have used (and loved!) Processwire for a long time. However, I have a new Processwire setup where I am having trouble logging on to the admin page for the first time.

I am running Processwire installed as an app on Yunohost, which uses nginx and mariaDB. At first my admin login page didn't show up, but after some tweaking of the nginx .conf files (as recommended here: 

) the admin page now appears. So far so good. 

But entering correct admin credentials has not allowed me to log in successfully for the first time.

What I have tried:

Attempt 1. Entering log in credentials created at Processwire setup

Result 1. Unable to log in. user and password boxes reset.

Attempt 2. Checking login username is correct in PHPMyAdmin by running @BitPoet's suggested query: https://processwire.com/talk/topic/26189-reset-admin-password-or-add-superuser-rol/?do=findComment&comment=217767

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

Also checked the 'pages' table: 

1938250078_Screenshot2024-01-17at5_38_03pm.thumb.png.f90fd10723d611cdc9c825d8c36219b0.png

Result 2. Superuser admin name I'm using is correct. 

Attempt 3. Re-setting credentials via a code snippet added to home.php, as recommended by @ryan in 2012: https://processwire.com/talk/topic/1736-forgot-backend-password-how-do-you-reset/?do=findComment&comment=16163

  1. Downloading the home.php file via SFTP.
  2. Adding the php inside the php code brackets at the top of the home.php file.
  3. Changing the admin and pass details to my own.
  4. Saving home.php locally.
  5. Uploading home.php via SFTP.
  6. In browser (Safari), refreshing view of my home page: https://domain.tld
  7. In browser (Safari), refreshing view of my admin page: https://domain.tld/processwire
  8. Entering new login details, press enter. Login page refreshes, deletes entries, does not log me in.

Result 3: No errors, but also can't log in using re-set credentials.

Attempt 4: Re-setting credentials via a code snippet by @kongondo above: https://processwire.com/talk/topic/26189-reset-admin-password-or-add-superuser-rol/?do=findComment&comment=217911

Result 4: Same steps as before, same result.

Attempt 5: Re-setting credentials via a code snippet by @bernhard above: https://processwire.com/talk/topic/26189-reset-admin-password-or-add-superuser-rol/?do=findComment&comment=217769

Result 5: Same steps as before, same result.

Attempt 6: Creating a tool.php file and adding code snippet to it as recommended by @Soma here: https://processwire.com/talk/topic/1736-forgot-backend-password-how-do-you-reset/?do=findComment&comment=16133

Result 6: Similar steps as before, but no noticeable change, and no successful login.

After this experiment, I deleted tool.php, but even so, my errors all refer to the tool.php file.

Quote

2024-01-16 21:40:49    guest   https://domain.tld/http404/  Fatal Error:  Uncaught Error: Call to undefined function wire() in /var/www/processwire/tool.php:3 Stack trace: #0 {main}   thrown (line 3 of /var/www/processwire/tool.php)

In PHPMyAdmin I see that I don't have any pages with a template_id of 3.

My question is: how do I manually (and safely!) add a page with an id of 3 in PHPMyAdmin so I can (hopefully!) log in to this Processwire install for the first time?

And also, if anyone has tips on anything else in my setup or process that I could tweak or try, I would be glad to hear!

Thank you for reading. ?

---

Update: I found a page for my superuser with id = 3. 

So next question: is there anything about using nginx with Processwire (an incorrect config perhaps?) that might prevent login details from successfully being setup in the database tables? And how might I fix it?

 

 

 

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...