Skip to content

Commit 9404250

Browse files
committed
Initial commit.
0 parents  commit 9404250

File tree

8 files changed

+197
-0
lines changed

8 files changed

+197
-0
lines changed

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Magento Admin Password Strength Enforcer
2+
3+
Your admin panel is home to *tons* of sensitive information—not something you want to expose to attackers easily. Unfortunately, if you have a lot of admin users and they're picking insecure passwords, you're opening yourself up to another vector of attack.
4+
5+
Magento's default rules for admin password strength are good, but they could be better. This extension is straightforward and small—it allows you to increase the required length of new admin passwords.
6+
7+
It is compact and does not modify any core code logic. It is upgrade safe and you should be able to install it on top of other extensions without worry.
8+
9+
## Setup
10+
11+
* Navigate to `System > Configuration > Admin Password Strength` in the Magento admin area
12+
* Set your desired admin password length
13+
* Done!
14+
15+
## Features
16+
17+
* After setup, all new admin passwords created will need to be the length you've set or larger
18+
* Defaults to a password length of >= 10 characters
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
class BranchLabs_AdminPasswordStrength_Helper_Data extends Mage_Core_Helper_Abstract {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
class BranchLabs_AdminPasswordStrength_Model_Observer {
3+
4+
// The admin 'Forgot Password' page is constructed in a weird way—without any layout handles.
5+
// I've resorted to an observer that creates and appends the JS validator block to get updated
6+
// functionality onto that page.
7+
public function addValidationToForgotAdminPassword($observer) {
8+
$template = $observer->getEvent()->getBlock()->getTemplate();
9+
if($template === "resetforgottenpassword.phtml") {
10+
$normalOutput = $observer->getTransport()->getHtml();
11+
$validator = Mage::app()->getLayout()
12+
->createBlock('adminhtml/template')
13+
->setTemplate('branchlabs/adminpasswordstrength/validator_js.phtml')
14+
->toHtml();
15+
$observer->getTransport()->setHtml($normalOutput . $validator);
16+
}
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0"?>
2+
<config>
3+
<modules>
4+
<BranchLabs_AdminPasswordStrength>
5+
<version>1.0.0</version>
6+
</BranchLabs_AdminPasswordStrength>
7+
</modules>
8+
<global>
9+
<blocks>
10+
<branchlabs_adminpasswordstrength>
11+
<class>BranchLabs_AdminPasswordStrength_Block</class>
12+
</branchlabs_adminpasswordstrength>
13+
</blocks>
14+
<helpers>
15+
<branchlabs_adminpasswordstrength>
16+
<class>BranchLabs_AdminPasswordStrength_Helper</class>
17+
</branchlabs_adminpasswordstrength>
18+
</helpers>
19+
<models>
20+
<branchlabs_adminpasswordstrength>
21+
<class>BranchLabs_AdminPasswordStrength_Model</class>
22+
</branchlabs_adminpasswordstrength>
23+
</models>
24+
</global>
25+
<adminhtml>
26+
<layout>
27+
<updates>
28+
<branchlabs_adminpasswordstrength>
29+
<file>branchlabs/adminpasswordstrength.xml</file>
30+
</branchlabs_adminpasswordstrength>
31+
</updates>
32+
</layout>
33+
<events>
34+
<core_block_abstract_to_html_after>
35+
<observers>
36+
<add_custom_admin_password_strength_validatior>
37+
<class>BranchLabs_AdminPasswordStrength_Model_Observer</class>
38+
<method>addValidationToForgotAdminPassword</method>
39+
</add_custom_admin_password_strength_validatior>
40+
</observers>
41+
</core_block_abstract_to_html_after>
42+
</events>
43+
<acl>
44+
<resources>
45+
<admin>
46+
<children>
47+
<system>
48+
<children>
49+
<config>
50+
<children>
51+
<adminpasswordstrength>
52+
<title>Admin Password Strength Settings</title>
53+
</adminpasswordstrength>
54+
</children>
55+
</config>
56+
</children>
57+
</system>
58+
</children>
59+
</admin>
60+
</resources>
61+
</acl>
62+
</adminhtml>
63+
<default>
64+
<adminpasswordstrength>
65+
<adminpasswordstrength_group>
66+
<minimum_character_length>10</minimum_character_length>
67+
</adminpasswordstrength_group>
68+
</adminpasswordstrength>
69+
</default>
70+
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<config>
3+
<tabs>
4+
<branchlabs translate="label" module="branchlabs_adminpasswordstrength">
5+
<label>BranchLabs</label>
6+
<sort_order>100</sort_order>
7+
</branchlabs>
8+
</tabs>
9+
<sections>
10+
<adminpasswordstrength translate="label" module="branchlabs_adminpasswordstrength">
11+
<label>Admin Password Strength</label>
12+
<tab>branchlabs</tab>
13+
<sort_order>1000</sort_order>
14+
<show_in_default>1</show_in_default>
15+
<show_in_website>0</show_in_website>
16+
<show_in_store>0</show_in_store>
17+
<groups>
18+
<adminpasswordstrength_group translate="label" module="branchlabs_adminpasswordstrength">
19+
<label>Admin Password Strength Settings</label>
20+
<frontend_type>text</frontend_type>
21+
<sort_order>1000</sort_order>
22+
<show_in_default>1</show_in_default>
23+
<show_in_website>0</show_in_website>
24+
<show_in_store>0</show_in_store>
25+
<fields>
26+
<minimum_character_length translate="label">
27+
<label>Minimum character length: </label>
28+
<comment>Must be greater than 7.</comment>
29+
<frontend_type>text</frontend_type>
30+
<validate>validate-digits</validate>
31+
<sort_order>20</sort_order>
32+
<show_in_default>1</show_in_default>
33+
<show_in_website>0</show_in_website>
34+
<show_in_store>0</show_in_store>
35+
</minimum_character_length>
36+
</fields>
37+
</adminpasswordstrength_group>
38+
</groups>
39+
</adminpasswordstrength>
40+
</sections>
41+
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<layout>
3+
4+
<!-- Admin user edit/create page under System > Permissions > Users -->
5+
<adminhtml_permissions_user_edit>
6+
<reference name="js">
7+
<block type="adminhtml/template" name="adminhtml.permissions.admin.password.validation.js" template="branchlabs/adminpasswordstrength/validator_js.phtml"/>
8+
</reference>
9+
</adminhtml_permissions_user_edit>
10+
11+
<!-- 'My Account' page under the System dropdown -->
12+
<adminhtml_system_account_index>
13+
<reference name="content">
14+
<block type="adminhtml/template" name="adminhtml.permissions.admin.password.validation.js" template="branchlabs/adminpasswordstrength/validator_js.phtml"/>
15+
</reference>
16+
</adminhtml_system_account_index>
17+
18+
</layout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
$l = Mage::getStoreConfig('adminpasswordstrength/adminpasswordstrength_group/minimum_character_length');
3+
$l = (is_numeric($l) && $l >= 7) ? $l : 7;
4+
?>
5+
<script type="text/javascript">
6+
if(typeof Validation == "function" && typeof Validation.addAllThese == "function" ) {
7+
Validation.addAllThese([
8+
['validate-admin-password', 'Please enter <?php echo $l; ?> or more characters. Password should contain both numeric and alphabetic characters.', function(v) {
9+
var pass=v.strip();
10+
if (0 == pass.length) {
11+
return true;
12+
}
13+
if (!(/[a-z]/i.test(v)) || !(/[0-9]/.test(v))) {
14+
return false;
15+
}
16+
return !(pass.length < <?php echo $l; ?>);
17+
}]
18+
]);
19+
}
20+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<config>
3+
<modules>
4+
<BranchLabs_AdminPasswordStrength>
5+
<active>true</active>
6+
<codePool>community</codePool>
7+
<depends></depends>
8+
</BranchLabs_AdminPasswordStrength>
9+
</modules>
10+
</config>

0 commit comments

Comments
 (0)