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 ! " ? $ % ^ & ).'); ?></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 ! " ? $ % ^ & ).'); ?></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 BACKUPInstall by downloading the files
- Download the fies here.
- Backup user-new.php and user-edit.php located in /wp-admin.
- Extract file in /wp-admin directory via ftp or scp.
Install by changing the files
- Open /wp-admin/user-new.php in your favorite editor (I use VIM)
- Find "<tr>" around line 118
- 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 -->
- Find "<input name="pass1" type="password" id="pass1" autocomplete="off" />" around line 138
- Add after <!-- Added By Lee Thompson of http://www.mysqlhow2.com --> <input type="button" value="Generate Password" onClick="passgen();" /> <!-- end add -->
- Find "<input name="pass2" type="password" id="pass2" autocomplete="off" />"
- 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 -->
- Save file.
- Open file /wp-admin/user-edit.php in your favorite editor (I use VIM)
- Find "tr id="password">" around line 295
- 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 -->
- Find "<input type="password" name="pass1" id="pass1" size="16" value="" autocomplete="off" />" around line 314
- Add after <!-- Added By Lee Thompson of http://www.mysqlhow2.com --> <input type="button" value="Generate Password" onClick="passgen();" /> <!-- end add -->
- Find "<input type="password" name="pass2" id="pass2" size="16" value="" autocomplete="off" />" around line 319
- 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 -->
- 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.




Posted in
Tags: 
