SSbits - Home page
Site by Carbon Crayon
Submit a Post >

Snippets - Little bits of code to make you happy

How to access your admin account when you've forgotten the password

I managed to forget my admin password and found quite a few ways to unlock an SS install. I originally thought about poking around the database and changing the hashes myself. After reviewing the Security and password encryption code, I would recommend against doing that. SilverStripe uses salted SHA1 encryption which is no fun to try and create yourself. Also you'd have to update multiple tables to get the password changed. Luckily the SS Core team has included multiple features for accomplishing this. The options below assume you have access to your webserver to use some PHP code.

Option 1 - Set a Default Admin Login

From: http://doc.silverstripe.com/doku.php?id=security#system_configuration

Add the following to your _config.php:

Security::setDefaultAdmin('adminuser', 'password');

Option 2 - Use an Environment Configuration file

From: http://doc.silverstripe.com/doku.php?id=environment-management
At the top level of your site folder create the file _ss_environment.php with the following code:

<?php
define('SS_DEFAULT_ADMIN_USERNAME', 'adminuser');
define('SS_DEFAULT_ADMIN_PASSWORD', 'password');
?>

Option 3 - Use a Member DataObject

In some page controller, config, or any interpreted php file:

$m = DataObject::get_one('Member', "Email = 'youradminaddress@email.com'");
$m->changePassword('password');

Note: You could also grab MemberID 1 if you also forgot your email address.  Member ID 1 should be the admin in most cases.

That's it!

You should be able to get back in your admin account using any of the above examples.  Now be a little more careful with those passwords, eh?

  • Darren-Lee
    09/04/2011 1:19pm (3 years ago)

    Such an important tip - when I first started using Silverstripe, late 2009, this post came in very handy indeed!

  • Richard
    06/02/2013 10:58pm (1 year ago)

    Still works, thank you and thank God because I was really stuck.

Post a comment ...

You cannot post comments until you have logged in. Login Here.

Advertisement

Site of the Month

Find SSbits on

Top Contributers

Rank Avatar Name
1 article image Aram Balakjian
2 article image Daniel Hensby
3 article image Marcus Dalgren
4 article image Hamish Campbell
5 article image Ty Barho
6 article image njorndare
7 article image Martijn van Nieuwenhoven
8 article image Darren-Lee
9 article image Roman Schmid
10 article image Matt Clegg

View full leaderboard


Advertisement