SHOW:
|
|
- or go back to the newest paste.
1 | <?php | |
2 | /* | |
3 | Plugin Name: Signup Password | |
4 | Plugin URI: | |
5 | Description: | |
6 | Author: Andrew Billits | |
7 | Version: 1.0.5 | |
8 | Author URI: | |
9 | */ | |
10 | ||
11 | /* | |
12 | Copyright 2007-2009 Incsub (http://incsub.com) | |
13 | ||
14 | This program is free software; you can redistribute it and/or modify | |
15 | it under the terms of the GNU General Public License (Version 2 - GPLv2) as published by | |
16 | the Free Software Foundation. | |
17 | ||
18 | This program is distributed in the hope that it will be useful, | |
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 | GNU General Public License for more details. | |
22 | ||
23 | You should have received a copy of the GNU General Public License | |
24 | along with this program; if not, write to the Free Software | |
25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
26 | */ | |
27 | ||
28 | //------------------------------------------------------------------------// | |
29 | //---Config---------------------------------------------------------------// | |
30 | //------------------------------------------------------------------------// | |
31 | $signup_password_use_encryption = 'no'; //Either 'yes' OR 'no' | |
32 | //------------------------------------------------------------------------// | |
33 | //---Hook-----------------------------------------------------------------// | |
34 | //------------------------------------------------------------------------// | |
35 | add_action('wp_head', 'signup_password_stylesheet'); | |
36 | add_action('signup_extra_fields', 'signup_password_fields'); | |
37 | add_filter('wpmu_validate_user_signup', 'signup_password_filter'); | |
38 | add_filter('signup_blogform', 'signup_password_fields_pass_through'); | |
39 | add_filter('add_signup_meta', 'signup_password_meta_filter',99); | |
40 | add_filter('random_password', 'signup_password_random_password_filter'); | |
41 | //------------------------------------------------------------------------// | |
42 | //---Functions------------------------------------------------------------// | |
43 | //------------------------------------------------------------------------// | |
44 | ||
45 | function signup_password_encrypt($data) { | |
46 | if(!isset($chars)) | |
47 | { | |
48 | // 3 different symbols (or combinations) for obfuscation | |
49 | // these should not appear within the original text | |
50 | $sym = array('¶', '¥xQ', '|'); | |
51 | ||
52 | foreach(range('a','z') as $key=>$val) | |
53 | $chars[$val] = str_repeat($sym[0],($key + 1)).$sym[1]; | |
54 | $chars[' '] = $sym[2]; | |
55 | ||
56 | unset($sym); | |
57 | } | |
58 | ||
59 | // encrypt | |
60 | $data = strtr(strtolower($data), $chars); | |
61 | return $data; | |
62 | ||
63 | } | |
64 | ||
65 | function signup_password_decrypt($data) { | |
66 | if(!isset($chars)) | |
67 | { | |
68 | // 3 different symbols (or combinations) for obfuscation | |
69 | // these should not appear within the original text | |
70 | $sym = array('¶', '¥xQ', '|'); | |
71 | ||
72 | foreach(range('a','z') as $key=>$val) | |
73 | $chars[$val] = str_repeat($sym[0],($key + 1)).$sym[1]; | |
74 | $chars[' '] = $sym[2]; | |
75 | ||
76 | unset($sym); | |
77 | } | |
78 | ||
79 | // decrypt | |
80 | $charset = array_flip($chars); | |
81 | $charset = array_reverse($charset, true); | |
82 | ||
83 | $data = strtr($data, $charset); | |
84 | unset($charset); | |
85 | return $data; | |
86 | } | |
87 | ||
88 | function signup_password_filter($content) { | |
89 | $password_1 = $_POST['password_1']; | |
90 | $password_2 = $_POST['password_2']; | |
91 | if ( !empty( $password_1 ) && $_POST['stage'] == 'validate-user-signup' ) { | |
92 | if ( $password_1 != $password_2 ) { | |
93 | $content['errors']->add('password', __('Passwords do not match.')); | |
94 | } | |
95 | } | |
96 | return $content; | |
97 | } | |
98 | ||
99 | function signup_password_meta_filter($meta) { | |
100 | global $signup_password_use_encryption; | |
101 | $password_1 = $_POST['password_1']; | |
102 | if ( !empty( $password_1 ) ) { | |
103 | if ( $signup_password_use_encryption == 'yes' ) { | |
104 | $password_1 = signup_password_encrypt($password_1); | |
105 | } | |
106 | $add_meta = array('password' => $password_1); | |
107 | $meta = array_merge($add_meta, $meta); | |
108 | } | |
109 | return $meta; | |
110 | } | |
111 | ||
112 | function signup_password_random_password_filter($password) { | |
113 | global $wpdb, $signup_password_use_encryption; | |
114 | ||
115 | if ( ! empty($_GET['key']) ) { | |
116 | $key = $_GET['key']; | |
117 | } else { | |
118 | $key = $_POST['key']; | |
119 | } | |
120 | if ( !empty($_POST['password_1']) ) { | |
121 | $password = $_POST['password_1']; | |
122 | } else if ( !empty( $key ) ) { | |
123 | $signup = $wpdb->get_row("SELECT * FROM " . $wpdb->signups . " WHERE activation_key = '" . $key . "'"); | |
124 | if ( empty($signup) || $signup->active ) { | |
125 | //bad key or already active | |
126 | } else { | |
127 | //check for password in signup meta | |
128 | $meta = unserialize($signup->meta); | |
129 | if ( !empty( $meta['password'] ) ) { | |
130 | if ( $signup_password_use_encryption == 'yes' ) { | |
131 | $password = signup_password_decrypt($meta['password']); | |
132 | } else { | |
133 | $password = $meta['password']; | |
134 | } | |
135 | } | |
136 | } | |
137 | } | |
138 | return $password; | |
139 | } | |
140 | ||
141 | //------------------------------------------------------------------------// | |
142 | //---Output Functions-----------------------------------------------------// | |
143 | //------------------------------------------------------------------------// | |
144 | ||
145 | function signup_password_stylesheet() { | |
146 | ?> | |
147 | <style type="text/css"> | |
148 | .mu_register #password_1, | |
149 | .mu_register #password_2 { width:100%; font-size: 24px; margin:5px 0; } | |
150 | </style> | |
151 | <?php | |
152 | } | |
153 | ||
154 | function signup_password_fields_pass_through() { | |
155 | if ( !empty( $_POST['password_1'] ) && !empty( $_POST['password_2'] ) ) { | |
156 | ?> | |
157 | <input type="hidden" name="password_1" value="<?php echo $_POST['password_1']; ?>" /> | |
158 | <?php | |
159 | } | |
160 | } | |
161 | ||
162 | function signup_password_fields($errors) { | |
163 | $error = $errors->get_error_message('password'); | |
164 | ?> | |
165 | <label for="password"><?php _e('Password'); ?>:</label> | |
166 | <?php | |
167 | if($error) { | |
168 | echo '<p class="error">' . $error . '</p>'; | |
169 | } | |
170 | ?> | |
171 | <input name="password_1" type="password" id="password_1" value="" autocomplete="off" maxlength="20" /><br /> | |
172 | (<?php _e('Leave fields blank for a random password to be generated.') ?>) | |
173 | <label for="password"><?php _e('Confirm Password'); ?>:</label> | |
174 | <input name="password_2" type="password" id="password_2" value="" autocomplete="off" maxlength="20" /><br /> | |
175 | (<?php _e('Type your new password again.') ?>) | |
176 | <?php | |
177 | } | |
178 | ||
179 | ?> |