· 7 years ago · Sep 07, 2018, 08:40 AM
1<?php
2
3function gvv_gTxt($what)
4 {
5 $lang = array(
6 'Password_all_back' => 'Please fill in all fields',
7 'Pass_er' => 'Passwords do not match',
8 'Old_pass_error' => 'You entered a wrong password!',
9 'Pass_ok' => 'password changed and sent to you by mail.',
10 'Smoll_pass' =>' You have a very simple password. Make it more than 7 characters. ',
11 'Unknow_err' => 'An error has occurred, please try again later',
12 'Email_er' => 'typed addresses do not match',
13 'Email_ok' => 'e-mail address changed.',
14 'Old_pass_err' => 'You entered a wrong password',
15 'Not_user' => 'No such promptness "Account Name" and "E-mail"!',
16 'Db_ok' => 'Database created.',
17 'Db_del_ok' => 'Base is removed',
18 'db_del_err' => 'Base has not been removed or was removed before.',
19 'Db_err' => 'You can not change, ask for help from the administration',
20 'Email_error' => 'E-mail is unreachable.',
21 'Install_db' => 'Install Database',
22 'Installing_db' => 'Install Base.',
23 'Deleting_db' => 'Remove the Base.',
24 'New_pass' => 'New password:',
25 'New_cpass' => 'Confirm password:',
26 'Old_pass' => 'Old password to confirm:',
27 'Submit' => 'Change',
28 'Mail_subject_new_pass' => 'password change.',
29 'Mail_body_pass' => 'Your new password',
30 'Time_out' => 'attempts ended, waiting for 10 minutes.',
31 'New_mail' => 'New E-mail',
32 'New_cmail' => 'Repeat E-mail',
33 'Pass_cmail' => 'Password to confirm',
34 'Your_name' => 'User Name',
35 'Your_mail' => 'Your E-mail',
36 'Submit_reset' => 'Send password',
37 'Reset_pass' =>' password reset.'
38 );
39
40 return $lang[$what];
41 }
42 //Create the administrative side
43if (@txpinterface == 'admin') {
44 add_privs('gvv_admin_edit', '1');
45 register_tab('extensions', 'gvv_admin_edit', gvv_gTxt('install_db'));
46 register_callback('gvv_step_gui', 'gvv_admin_edit');
47}
48
49function gvv_step_gui($event, $step)
50{
51 if(!$step or !in_array($step, array(
52 'gvv_add_db',
53 'gvv_delet_db',
54 ))) {
55 gvv_add_tab_edit_list();
56 } else $step();
57}
58 //Making her look, very simple yet
59 function gvv_add_tab_edit_list()
60 {
61 pagetop('My plugin tab');
62 echo '<ul>';
63 echo '<li><a href="?event=gvv_admin_edit&step=gvv_add_db">'.gvv_gTxt('installing_db').'</a></li>';
64 echo '<li><a href="?event=gvv_admin_edit&step=gvv_delet_db">'.gvv_gTxt('deleting_db').'</a></li>';
65 echo '</ul>';
66}
67 //Creating a table if you wish, that would immediately
68function gvv_add_db()
69 {
70 safe_query("CREATE TABLE IF NOT EXISTS ".safe_pfx('gvv_user_edit')." (name VARCHAR (64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL UNIQUE, repet int not null, time int)");
71 echo gvv_gTxt('db_del_ok');
72 gvv_add_tab_edit_list();
73 }
74 //Deleting a table if you want
75 function gvv_delet_db()
76 {
77 if(safe_query("DROP TABLE ".safe_pfx('gvv_user_edit').""));
78 {
79 echo gvv_gTxt('db_del_ok');
80 gvv_add_tab_edit_list();
81 }
82 else
83 {
84 echo gvv_gTxt('db_del_err');
85 }
86 }
87
88 //Function that would look how many times user tried to try a password
89function gvv_query_db ($name)
90{ //Check whether user in the table
91 if(safe_count(safe_pfx('gvv_user_edit'), "name = '".doSlash($name)."'") == 1)
92 {
93 $repet = safe_field('repet', safe_pfx('gvv_user_edit'), "name = '".doSlash($name)."'");
94 //check how many once tried to remember the password
95 if ($repet < 5)
96 { //If less than 5 once, then add 1 and return to "allowed to try"
97 $repet = $repet + 1;
98 safe_update(safe_pfx('gvv_user_edit'), "repet = '$repet'", "name = '".doSlash($name)."'");
99 return ;
100 }
101 else
102 { //consider whether the time recorded
103 $time = safe_field('time',safe_pfx('gvv_user_edit')," name = '".doSlash($name)."'");
104 if(!empty($time)) //time is not?
105 {
106 if($time > time()) //time more than now
107 {
108 $a=1;
109 return $a; // relax and remember your password
110 }
111 else
112 { //otherwise you can make an attempt initially
113 $repet = 1;
114 safe_update(safe_pfx('gvv_user_edit'), "repet = '$repet', time = ''", "name = '".doSlash($name)."'");
115 return ;
116 }
117 }
118 else
119 { //if there was no time, then write to the table time of 10 minutes
120 $time = time() + 600;
121 safe_update(safe_pfx('gvv_user_edit'), "time = '$time'", "name = '".doSlash($name)."'");
122 $a=1;
123 return $a;
124 }
125 }
126 }
127 else
128 { //If the user does not
129 $repet = 1;
130 safe_insert(safe_pfx('gvv_user_edit'), "repet = '$repet', name = '".doSlash($name)."'");
131 return ;
132 }
133}
134
135//Function representing the form
136function gvv_form_edit_pass()
137{
138 global $txp_user;
139
140 $form_edit_pass = '<form action="'.$_SERVER['REQUEST_URI'].'" method="post">'.'
141<input type="hidden" name="stage_pass" value="1">
142<div class="selfedit">
143<input name="name" value='.$txp_user.' type="hidden">
144<div id="acaunt_name"><label>'.gvv_gTxt('new_pass').'</div>
145<div id="acaunt_id"><input name="new_pass" value="" id="password" type="password"></label></div>
146<div style="clear: both;"></div>
147<div id="acaunt_name"><label>'.gvv_gTxt('new_cpass').'</div>
148<div id="acaunt_id"><input name="cnew_pass" value="" id="password" type="password"></label></div>
149<div style="clear: both;"></div>
150<div id="acaunt_name"><label>'.gvv_gTxt('old_pass').'</div>
151<div id="acaunt_id"><input name="oldpass" value="" id="password" type="password"></label></div>
152<div style="clear: both;"></div>
153<div id="save_acaunt"><input value="'.gvv_gTxt('submit').'" type="submit"></label></div>
154</div></form>';
155 return $form_edit_pass;
156}
157
158//The Change Password
159function gvv_edit_pass($form_edit_pass)
160{
161 if (!isset($_POST['stage_pass']))
162 {
163 return gvv_form_edit_pass(); //if stage_pass NULL, then representing the form
164 }
165 else
166 { //else extract
167 extract(gpsa(array('new_pass', 'cnew_pass', 'oldpass', 'name')));
168 if (!empty($new_pass) and !empty($cnew_pass) and !empty($oldpass)) //if field is not NULL
169 {
170 if (8 <= mb_strlen($new_pass)) //if the password longer than 8 characters
171 {
172 if ($new_pass != $cnew_pass) // check whether the passwords match
173 {
174 return gvv_gTxt('pass_er');
175 }
176 else
177 {
178 $a=gvv_query_db ($name); //Look, if there were attempts to change your password or email
179 if ($a == 1)
180 {
181 return gvv_gTxt('time_out');
182 }
183 else
184 { //Consider, if the password is entered correctly
185 if(safe_count(safe_pfx('txp_users'), "(pass=password('".doSlash($oldpass)."') or pass=password(lower('".doSlash($oldpass)."'))) and name='".doSlash($name)."'") == 1)
186 {
187 $rs = safe_update(safe_pfx('txp_users'), "pass = password(lower('".doSlash($new_pass)."'))", "name = '".doSlash($name)."'");
188 safe_delete(safe_pfx('gvv_user_edit'), "name = '".doSlash($name)."'");
189 if($rs)
190 { //if so then send a message
191 $to_address = safe_field('email',safe_pfx('txp_users')," name = '".doSlash($name)."'");
192 $site_name = site_name();
193 $site_url = site_url();
194 $subject = "$site_name:".gvv_gTxt('mail_subject_new_pass');
195 $body = "\n".gvv_gTxt('mail_body_pass').": $new_pass \n$site_url";
196 txpMail($to_address, $subject, $body);
197 return gvv_gTxt('pass_ok');
198 }
199 else
200 {
201 return gvv_gTxt('unknow_err');
202 }
203 }
204 else
205 {
206 return gvv_gTxt('old_pass_error');
207 }
208 }
209 }
210 }
211 else
212 {
213 return gvv_gTxt('smoll_pass');
214 }
215 }
216 else
217 {
218 return gvv_gTxt('password_all_back');
219 }
220 }
221}
222
223 //Function representing the form
224function gvv_form_edit_email()
225{
226 global $txp_user;
227
228 $form_edit_email = '<form action="'.$_SERVER['REQUEST_URI'].'" method="post">'.'
229<input type="hidden" name="stage_email" value="1">
230<input name="name" value='.$txp_user.' type="hidden">
231<div class="selfedit">
232<div id="acaunt_name"><label>'.gvv_gTxt('new_email').':</div>
233<div id="acaunt_id"><input name="email" value="" id="email" type="text"></label></div>
234<div style="clear: both;"></div>
235<div id="acaunt_name"><label>'.gvv_gTxt('new_cmail').':</div>
236<div id="acaunt_id"><input name="cemail" value="" id="email" type="text"></label></div>
237<div style="clear: both;"></div>
238<div id="acaunt_name"><label>'.gvv_gTxt('pass_cmail').':</div>
239<div id="acaunt_id"><input name="oldpass" value="" id="password" type="password"></label></div>
240<div style="clear: both;"></div>
241<div id="save_acaunt"><input value="'.gvv_gTxt('submit').'" type="submit"></label></div>
242</div></form>';
243
244 return $form_edit_email;
245}
246
247//The Change E-mail
248function gvv_edit_email($form_edit_email)
249{
250 if (!isset($_POST['stage_email']))
251 {
252 return gvv_form_edit_email();
253 }
254 else
255 {
256 extract(gpsa(array('email', 'cemail', 'oldpass', 'name')));
257 if (!empty($email) and !empty($cemail) and !empty($oldpass))
258 {
259 if (!filter_var($email, FILTER_VALIDATE_EMAIL))
260 {
261 return gvv_gTxt('email_error');
262 }
263 else
264 {
265 if ($email != $cemail)
266 {
267 return gvv_gTxt('email_er');
268 }
269 else
270 {
271 $a=gvv_query_db ($name);
272 if ($a == 1)
273 {
274 return gvv_gTxt('time_out');
275 }
276 else
277 {
278 if(safe_count(safe_pfx('txp_users'), "(pass=password('".doSlash($oldpass)."')) or pass=password(lower('".doSlash($oldpass)."')) and name='".doSlash($name)."'") == 1)
279 {
280 safe_update(safe_pfx('txp_users'), "email = '".doSlash($email)."'", "name = '".doSlash($name)."'");
281 safe_delete(safe_pfx('gvv_user_edit'), "name = '".doSlash($name)."'");
282 return gvv_gTxt('email_ok');
283 }
284 else
285 {
286 return gvv_gTxt('old_pass_err');
287 }
288 }
289 }
290 }
291 }
292 else
293 {
294 return gvv_gTxt('password_all_back');
295 }
296 }
297}
298
299//password reset the form
300function gvv_form_reset_pass()
301{
302 $form_reset_pass = '<form action="'.$_SERVER['REQUEST_URI'].'" method="post">'.'
303<input type="hidden" name="stage_reset" value="1">
304<div class="selfedit">
305<div id="name_reg"><label>'.gvv_gTxt('your_name').':</div><div id="id_reg">
306<input name="name" value="" id="name_reset" type="text">
307</label></div>
308<div id="name_reg"><label>'.gvv_gTxt('your_mail').':</div><div id="id_reg">
309<input name="email" value="" id="email_reset" type="text">
310</label></div><label>
311<div id="submit_reg"><label><input value="'.gvv_gTxt('submit_reset').'" type="submit">
312</label></div></div></form>';
313
314 return $form_reset_pass;
315}
316
317//password reset the function
318function gvv_reset_pass($form_reset_pass)
319{
320 if (!isset($_POST['stage_reset']))
321 {
322 return gvv_form_reset_pass();
323 }
324 else
325 {
326 extract(gpsa(array('email', 'name')));
327 if (!empty($name) and !empty($email))
328 {
329 if (!filter_var($email, FILTER_VALIDATE_EMAIL))
330 {
331 return gvv_gTxt('email_error');
332 }
333 else
334 {
335 if(safe_count(safe_pfx('txp_users'), "email='".doSlash($email)."' and name='".doSlash($name)."'") == 1)
336 {
337 $pass = doSlash(generate_password(10));
338 $rs = safe_update(safe_pfx('txp_users'), "pass = password(lower('$pass'))", "name = '".doSlash($name)."'");
339 if($rs)
340 {
341 $to_address = $email;
342 $site_name = site_name();
343 $site_url = site_url();
344 $subject = "$site_name: ".gvv_gTxt('reset_pass');
345 $body = "\n".gvv_gTxt('mail_body_pass').": $new_pass \n$site_url";
346 txpMail($to_address, $subject, $body);
347 return gvv_gTxt('pass_ok');
348 }
349 else
350 {
351 return gvv_gTxt('unknow_err');
352 }
353 }
354 else
355 {
356 return gvv_gTxt('not_user');
357 }
358 }
359 }
360 else
361 {
362 return gvv_gTxt('password_all_back');
363 }
364 }
365}
366
367?>