-
Notifications
You must be signed in to change notification settings - Fork 5
/
forgot.php
94 lines (80 loc) · 2.68 KB
/
forgot.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
# ***** BEGIN LICENSE BLOCK *****
# This file is part of Nevertable .
# Copyright (c) 2004 Francois Guillet and contributors. All rights
# reserved.
#
# Nevertable is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Nevertable is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Nevertable; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ***** END LICENSE BLOCK *****
define('ROOT_PATH', "./");
define('NVRTBL', 1);
include_once ROOT_PATH ."config.inc.php";
include_once ROOT_PATH ."includes/common.php";
include_once ROOT_PATH ."includes/classes.php";
//args process
$args = get_arguments($_POST, $_GET);
$table = new Nvrtbl();
try {
if(isset($args['run']))
{
if (empty($args['email']))
throw new Exception($lang['FORGOT_EMPTY_MAIL']);
$res = $table->db->helper->SelectUserByMail($args['email']);
if ($table->db->NumRows() == 0) // pas trouvé
{
throw new Exception ($lang['FORGOT_INVALID_MAIL']);
}
$val = $table->db->FetchArray($res);
$keychars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$length = 8;
$newpass = "";
$max=strlen($keychars)-1;
for ($i=0;$i<$length;$i++)
$newpass .= substr($keychars, rand(0, $max), 1);
//Update password
if (!isset($val['id']))
exit;
$table->db->NewQuery("UPDATE", "users");
$table->db->UpdateSet(array("passwd" => Auth::Hash($newpass)));
$table->db->Where("id", $val['id']);
$table->db->Limit(1);
$table->db->Query();
//envoie du mail
$m= new Mail; // create the mail
$m->From( $config['admin_mail']);
$m->To($args['email']);
$m->Subject( "Nevertable : password recovery" );
$message = "Try this... \n\n";
$message .= " login : ".$val['pseudo']."\n";
$message .= " password : ".$newpass."\n\n";
$message .= "See you soon !";
$m->Body( $message); // set the body
$m->Send(); // send the mail
$tpl_params = array();
$tpl_params['message_array'] = array($lang['FORGOT_EMAIL_SENT']);
$tpl_params['delay'] = 0;
$tpl_params['redirect'] = "index.php";
$table->template->Show('redirect', $tpl_params);
}
else
{
$table->template->Show('forgot');
}
} catch (Exception $ex)
{
$table->template->Show('error', array("exception" => $ex));
}
$table->Close();