Permalink
Browse files

initial

  • Loading branch information...
0 parents commit d3bfdf57cda1e22deddcfea535d0311310fe592c @soulseekah committed Mar 6, 2012
@@ -0,0 +1,41 @@
+=== Random New User Password ===
+Contributors: soulseekah
+Tags: users, passwords
+Requires at least: 3.0
+Tested up to: 3.3.1
+Stable tag: 0.1
+
+Simple (for now) plugin to generate a random password when creating a new user from the Dashboard.
+
+== Description ==
+
+Inspired by [http://wordpress.org/extend/ideas/topic/random-password-for-new-users](http://wordpress.org/extend/ideas/topic/random-password-for-new-users) and a couple of hours of free time, this JavaScript-powered plugin adds a button to the Add User screen, which, when clicked, generates a strong random password for your new user. This should shave off a couple of seconds of your time when creating a new user.
+
+Props to [@lorenzopopov](http://twitter.com/lorenzopopov) for the random dice image.
+
+== Installation ==
+
+Nothing special.
+
+1. Upload plugin folder to the `/wp-content/plugins/` directory
+2. Activate the plugin through the 'Plugins' menu in WordPress
+3. Generate secure random passwords
+
+== Frequently Asked Questions ==
+
+= Can I see the password that got generated? =
+
+Only if you really want to.
+
+= How do I get it to...? =
+
+Doesn't do much at the moment. Send over your feature requests or even code and they'll be implemented as soon as possible.
+
+== Screenshots ==
+
+1. Add some randomness and save some time...
+
+== Changelog ==
+
+= 0.1 =
+* Initial
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
@@ -0,0 +1,28 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: \n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2012-03-06 14:56+0500\n"
+"PO-Revision-Date: \n"
+"Last-Translator: Gennady Kovshenin <gennady@kovshenin.com>\n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Poedit-KeywordsList: __;_e\n"
+"X-Poedit-Basepath: /home/soulseekah/www/wordpress.lo/wp-content/plugins/\n"
+"X-Poedit-Language: English\n"
+"X-Poedit-SearchPath-0: random-new-user-password\n"
+
+#: random-new-user-password/random-new-user-password.php:42
+msgid "Generate a random one"
+msgstr ""
+
+#: random-new-user-password/random-new-user-password.php:52
+msgid "JavaScript has to be switched on to generate random user passwords."
+msgstr ""
+
+#: random-new-user-password/random-new-user-password.php:54
+msgid "Passwords are disabled. See the `show_password_fields` hook."
+msgstr ""
+
@@ -0,0 +1,50 @@
+/* Random Password Generation for New Users */
+
+jQuery(document).ready(function() {
+ /* remove "No JavaScript" warning */
+ jQuery( "#password_generator_no_js" ).remove();
+
+ var pass_label = jQuery( "label[for=pass1]" );
+ if ( pass_label) {
+
+ /* insert button, if passwords are enabled (see `show_password_fields` hook) */
+ password_generator = "<div id=\"password_generator\"><a href=\"#\">"+AddNewUser_GenPassword_Strings.generator_link_text+"</a></div>";
+ pass_label.append(password_generator); /* attach password button */
+
+ jQuery( "#password_generator" ).click(function(e) {
+
+ var password = AddNewUser_GenPassword.generate_password(12); /* generate a random password */
+ /* set random password, trigger "keyup" event to refresh strength indicator */
+ jQuery( "#pass1" ).val(password).trigger( "keyup" );
+ jQuery( "#pass2" ).val(password).trigger( "keyup" );
+
+ /* assume the default - Send user the password */
+ jQuery( "#send_password" ).attr( "checked", "checked" );
+
+ /* todo: provide more control over the nature of the password */
+
+ e.preventDefault(); /* don't jump */
+ return false;
+
+ }); /* attach event listener */
+ }
+});
+
+var AddNewUser_GenPassword = {}
+AddNewUser_GenPassword.generate_password = function( password_length ) {
+
+ var characters, chars_length, char_picked, password = "";
+ if ( typeof length == "undefined" ) length = 8; /* default length */
+
+ /* characters */
+ characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
+ chars_length = characters.length;
+
+ while ( password_length-- ) {
+ /* not the best generator in the world */
+ char_picked = Math.floor(Math.random() * 1000000) % chars_length;
+ password += characters.charAt(char_picked);
+ }
+
+ return password;
+}
@@ -0,0 +1,65 @@
+<?php
+ /*
+ Plugin Name: Random New User Password
+ Description: Gives the ability to generate random passwords for new users added
+ Plugin URI: http://codeseekah.com/2012/03/06/random-new-user-password-generator-for-wordpress
+ Version: 0.1
+ Author: Gennady Kovshenin
+ Author URI: http://codeseekah.com
+ License: GPL2
+ */
+
+ class AddNewUser_GenPassword {
+ private $text_domain;
+
+ public function __construct() {
+ $this->text_domain = 'random_new_user_password';
+ add_action( 'init', array( $this, 'init' ) );
+ }
+
+ public function init() {
+ load_plugin_textdomain( $this->text_domain, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
+ $this->add_filters(); /* let's go catch some fish */
+ }
+
+ private function add_filters() {
+ /* display only in `user-new.php` part of the Dashboard */
+ add_action( 'admin_head-user-new.php', array( $this, 'show_password_generator' ) );
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts_n_styles' ) );
+ }
+
+ public function show_password_generator() {
+ /* display any errors that may prevent the plugin from doing its job */
+ add_filter( 'show_password_fields', array( $this, 'show_password_generator_warnings' ), null, 999 );
+ /* would like to run last, so we know that if any other entity deactivated the fields */
+ }
+
+ public function enqueue_scripts_n_styles( $hook ) {
+ if ( $hook != 'user-new.php' ) return;
+ wp_enqueue_script( 'random-new-user-password', plugins_url( '/random-new-user-password.js', __FILE__ ), array( 'jquery' ), '0.1' );
+
+ /* localize */
+ $data = array(
+ 'generator_link_text' => __( 'Generate a random one', $this->text_domain )
+ );
+ wp_localize_script( 'random-new-user-password', 'AddNewUser_GenPassword_Strings', $data );
+
+ wp_enqueue_style( 'random-new-user-password', plugins_url( '/style.css', __FILE__ ), array(), '0.1' );
+ }
+
+ public function show_password_generator_warnings( $show_password_fields ) {
+ /* `show_password_fields` can be set to false (see wp-admin/user-new.php) */
+ if ( $show_password_fields ) {
+ echo '<tr class="form-field"><th scope="row" colspan="2"><div id="password_generator_no_js" class="error">' . __( 'JavaScript has to be switched on to generate random user passwords.', $this->text_domain ) . '</div></th>';
+ } else {
+ echo '<tr class="form-field"><th scope="row" colspan="2"><div class="error">' . __( 'Passwords are disabled. See the `show_password_fields` hook.', $this->text_domain ).'</div></th></tr>';
+ }
+
+ return $show_password_fields;
+ }
+ }
+
+ /* Run only in WordPress context, thanks */
+ if ( defined('WP_CONTENT_DIR') ) new AddNewUser_GenPassword;
+
+?>
@@ -0,0 +1,41 @@
+=== Random New User Password ===
+Contributors: soulseekah
+Tags: users, passwords
+Requires at least: 3.0
+Tested up to: 3.3.1
+Stable tag: 0.1
+
+Simple (for now) plugin to generate a random password when creating a new user from the Dashboard.
+
+== Description ==
+
+Inspired by [http://wordpress.org/extend/ideas/topic/random-password-for-new-users](http://wordpress.org/extend/ideas/topic/random-password-for-new-users) and a couple of hours of free time, this JavaScript-powered plugin adds a button to the Add User screen, which, when clicked, generates a strong random password for your new user. This should shave off a couple of seconds of your time when creating a new user.
+
+Props to [@lorenzopopov](http://twitter.com/lorenzopopov) for the random dice image.
+
+== Installation ==
+
+Nothing special.
+
+1. Upload plugin folder to the `/wp-content/plugins/` directory
+2. Activate the plugin through the 'Plugins' menu in WordPress
+3. Generate secure random passwords
+
+== Frequently Asked Questions ==
+
+= Can I see the password that got generated? =
+
+Only if you really want to.
+
+= How do I get it to...? =
+
+Doesn't do much at the moment. Send over your feature requests or even code and they'll be implemented as soon as possible.
+
+== Screenshots ==
+
+1. Add some randomness and save some time...
+
+== Changelog ==
+
+= 0.1 =
+* Initial
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,5 @@
+#password_generator {
+ background: url(images/random_dice.png) no-repeat;
+ height: 85px;
+ background-position-y: 23px;
+}

0 comments on commit d3bfdf5

Please sign in to comment.