WordPress Idea’s Password Suggestion

I was looking around WordPress.org at idea’s, that the community was suggesting. I took the Password Suggestion idea and made a small change to 2 of the core scripts. This change will give the administrator of a blog the ability to randomly generate password for users they are adding or editing. This was a 5 min project and you can see the changes below. I have also made it possible to see plain text passwords in the password fields. I don’t know if I am suppose to release stuff like this for WordPress and I hope I have not offended anyone on the core development team.

Add User
<pre><?php if ( apply_filters('show_password_fields', true) ) : ?>
        <tr>

        <!-- Added By Lee Thompson of http://www.mysqlhow2.com -->
        <script language="javascript" type="text/javascript">
        function passgen() {
         var chars = "0123456789abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()";
         var string_length = 10;
         var passgen = '';
         for (var i=0; i<string_length; i++) {
          var rnum = Math.floor(Math.random() * chars.length);
          passgen += chars.substring(rnum,rnum+1);
         }
         document.adduser.pass1.value = passgen;
         document.adduser.pass2.value = passgen;
        }

        </script>
        <!-- end add -->

                <th scope="row"><label for="pass1"><?php _e('Password'); ?> <span><?php _e('(twice, required)'); ?></span></label></th>
                <td><input name="pass1" type="password" id="pass1" autocomplete="off" />
                <!-- Added By Lee Thompson of http://www.mysqlhow2.com -->
                <input type="button" value="Generate Password" onClick="passgen();" />
                <!-- end add -->
                <br />
                <input name="pass2" type="password" id="pass2" autocomplete="off" />
                <!-- Added By Lee Thompson of http://www.mysqlhow2.com -->
                <input type="checkbox" onchange="document.getElementById('pass1').type = this.checked ? 'text' : 'password'; document.getElementById('pass2').type = this.checked ? 'text' : 'password'" /> Show passwords
                <!-- end add -->
                <br />
                <div id="pass-strength-result"><?php _e('Strength indicator'); ?></div>
                <p><?php _e('Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ &amp; ).'); ?></p>
                </td>
        </tr>
        <tr>
</pre>

Edit User

<pre>
$show_password_fields = apply_filters('show_password_fields', true, $profileuser);
if ( $show_password_fields ) :
?>
<tr id="password">
<!-- Added By Lee Thompson of http://www.mysqlhow2.com -->
        <script language="javascript" type="text/javascript">
        function passgen() {
         var chars = "0123456789abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()";
         var string_length = 10;
         var passgen = '';
         for (var i=0; i<string_length; i++) {
          var rnum = Math.floor(Math.random() * chars.length);
          passgen += chars.substring(rnum,rnum+1);
         }
         document.getElementById('pass1').value = passgen;
         document.getElementById('pass2').value = passgen;
        }

        </script>
        <!-- end add -->

        <th><label for="pass1"><?php _e('New Password'); ?></label></th>
        <td><input type="password" name="pass1" id="pass1" size="16" value="" autocomplete="off" />
                <!-- Added By Lee Thompson of http://www.mysqlhow2.com -->
                <input type="button" value="Generate Password" onClick="passgen();" />
                <!-- end add -->
                 <span><?php _e("If you would like to change the password type a new one. Otherwise leave this blank."); ?></span><br />
                <input type="password" name="pass2" id="pass2" size="16" value="" autocomplete="off" />
                <!-- Added By Lee Thompson of http://www.mysqlhow2.com -->
                <input type="checkbox" onchange="document.getElementById('pass1').type = this.checked ? 'text' : 'password'; document.getElementById('pass2').type = this.checked ? 'text' : 'password'" /> Show passwords
                <!-- end add -->
                <span><?php _e("Type your new password again."); ?></span><br />

                <div id="pass-strength-result"><?php _e('Strength indicator'); ?></div>
                <p><?php _e('Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ &amp; ).'); ?></p>
        </td>
</tr>
<?php endif; ?>
</pre>

Installation is pretty easy

But first I can not stress this enough as you will be changing core scripts. I am not responsible if it breaks your site.
BACKUP BACKUP BACKUP

Install by downloading the files

  1. Download the fies here.
  2. Backup user-new.php and user-edit.php located in /wp-admin.
  3. Extract file in /wp-admin directory via ftp or scp.
Install by changing the files
  1. Open /wp-admin/user-new.php in your favorite editor (I use VIM)
  2. Find "<tr>" around line 118
  3. Add after <!-- Added By Lee Thompson of http://www.mysqlhow2.com --> <script language="javascript" type="text/javascript"> function passgen() { var chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()"; var string_length = 10; var passgen = ''; for (var i=0; i<string_length; i++) { var rnum = Math.floor(Math.random() * chars.length); passgen += chars.substring(rnum,rnum+1); } document.adduser.pass1.value = passgen; document.adduser.pass2.value = passgen; } </script> <!-- end add -->
  4. Find "<input name="pass1" type="password" id="pass1" autocomplete="off" />" around line 138
  5. Add after <!-- Added By Lee Thompson of http://www.mysqlhow2.com --> <input type="button" value="Generate Password" onClick="passgen();" /> <!-- end add -->
  6. Find "<input name="pass2" type="password" id="pass2" autocomplete="off" />"
  7. Add after <!-- Added By Lee Thompson of http://www.mysqlhow2.com --> <input type="checkbox" onchange="document.getElementById('pass1').type = this.checked ? 'text' : 'password'; document.getElementById('pass2').type = this.checked ? 'text' : 'password'" /> Show passwords <!-- end add -->
  8. Save file.
  9. Open file /wp-admin/user-edit.php in your favorite editor (I use VIM)
  10. Find "tr id="password">" around line 295
  11. Add after <!-- Added By Lee Thompson of http://www.mysqlhow2.com --> <script language="javascript" type="text/javascript"> function passgen() { var chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()"; var string_length = 10; var passgen = ''; for (var i=0; i<string_length; i++) { var rnum = Math.floor(Math.random() * chars.length); passgen += chars.substring(rnum,rnum+1); } document.getElementById('pass1').value = passgen; document.getElementById('pass2').value = passgen; } </script> <!-- end add -->
  12. Find "<input type="password" name="pass1" id="pass1" size="16" value="" autocomplete="off" />" around line 314
  13. Add after <!-- Added By Lee Thompson of http://www.mysqlhow2.com --> <input type="button" value="Generate Password" onClick="passgen();" /> <!-- end add -->
  14. Find "<input type="password" name="pass2" id="pass2" size="16" value="" autocomplete="off" />" around line 319
  15. Add after <!-- Added By Lee Thompson of http://www.mysqlhow2.com --> <input type="checkbox" onchange="document.getElementById('pass1').type = this.checked ? 'text' : 'password'; document.getElementById('pass2').type = this.checked ? 'text' : 'password'" /> Show passwords <!-- end add -->
  16. Save File.

Well I hope this helps the administrators that are looking for a random password generator, in the administration section for adding and editing users.

VN:F [1.9.3_1094]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)
You can skip to the end and leave a response. Pinging is currently not allowed.

Leave a Reply

You must be logged in to post a comment.

Twitter Delicious Facebook Digg Stumbleupon Favorites More
Designed by: MySQL How 2

Switch to our mobile site