From 87b11549895770931f960e45e066c090140bc175 Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 25 Apr 2008 17:12:25 +0000 Subject: [PATCH] Add arg to make special chars optional when generating passwords. fixes #6842 for trunk git-svn-id: http://svn.automattic.com/wordpress/trunk@7836 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/pluggable.php | 7 +++++-- wp-login.php | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php index 5550d9a0a4..ccd5f4111a 100644 --- a/wp-includes/pluggable.php +++ b/wp-includes/pluggable.php @@ -1168,8 +1168,11 @@ if ( !function_exists('wp_generate_password') ) : * * @return string The random password **/ -function wp_generate_password($length = 12) { - $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()"; +function wp_generate_password($length = 12, $special_chars = true) { + $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; + if ( $special_chars ) + $chars .= '!@#$%^&*()'; + $password = ''; for ( $i = 0; $i < $length; $i++ ) $password .= substr($chars, mt_rand(0, strlen($chars) - 1), 1); diff --git a/wp-login.php b/wp-login.php index af9b161093..e615f0a414 100644 --- a/wp-login.php +++ b/wp-login.php @@ -93,7 +93,7 @@ function retrieve_password() { $key = $wpdb->get_var($wpdb->prepare("SELECT user_activation_key FROM $wpdb->users WHERE user_login = %s", $user_login)); if ( empty($key) ) { // Generate something random for a key... - $key = wp_generate_password(); + $key = wp_generate_password(20, false); do_action('retrieve_password_key', $user_login, $key); // Now insert the new md5 key into the db $wpdb->query($wpdb->prepare("UPDATE $wpdb->users SET user_activation_key = %s WHERE user_login = %s", $key, $user_login));