Skip to content

Commit 9ab66a5

Browse files
author
Marius Burkard
committed
- Added password request activation link (Closes #2933)
1 parent 34c940e commit 9ab66a5

File tree

5 files changed

+78
-6
lines changed

5 files changed

+78
-6
lines changed

install/sql/incremental/upd_dev_collection.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,7 @@ ALTER TABLE `client` ADD COLUMN `limit_ssl_letsencrypt` enum('n','y') NOT NULL D
216216
ALTER TABLE `client_template` ADD COLUMN `limit_ssl_letsencrypt` enum('n','y') NOT NULL DEFAULT 'n' AFTER `limit_ssl`;
217217
ALTER TABLE `client` ADD COLUMN `limit_directive_snippets` ENUM( 'n', 'y' ) NOT NULL DEFAULT 'n' AFTER `limit_backup`;
218218
ALTER TABLE `client_template` ADD COLUMN `limit_directive_snippets` ENUM( 'n', 'y' ) NOT NULL DEFAULT 'n' AFTER `limit_backup`;
219+
220+
ALTER TABLE `sys_user`
221+
ADD COLUMN `lost_password_hash` VARCHAR(50) NOT NULL DEFAULT '',
222+
ADD COLUMN `lost_password_reqtime` DATETIME NULL default NULL;

install/sql/ispconfig3.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,6 +1791,8 @@ CREATE TABLE `sys_user` (
17911791
`id_rsa` VARCHAR( 2000 ) NOT NULL default '',
17921792
`ssh_rsa` VARCHAR( 600 ) NOT NULL default '',
17931793
`lost_password_function` tinyint(1) NOT NULL default '1',
1794+
`lost_password_hash` VARCHAR(50) NOT NULL default '',
1795+
`lost_password_reqtime` DATETIME NULL default NULL,
17941796
PRIMARY KEY (`userid`)
17951797
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
17961798

interface/web/login/lib/lang/de.lng

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ $wb['error_user_blocked'] = 'Benutzer ist gesperrt.';
55
$wb['error_user_too_many_logins'] = 'Zu viele falsche Logins. Bitte warten Sie 15 Minuten.';
66
$wb['pass_reset_txt'] = 'Ein neues Passwort wird generiert und an die E-Mail Adresse, die in ihren Benutzereinstellungen hinterlegt ist, gesendet, wenn Ihre eingegeben E-Mail-Adresse mit der hinterlegten E-Mail-Adresse übereinstimmt.';
77
$wb['pw_reset'] = 'Das Passwort wurde zurückgesetzt und wird per E-Mail an Sie geschickt.';
8+
$wb['pw_reset_act'] = 'Ein Aktivierungslink wurde per E-Mail an Sie geschickt. Bitte bestätigen Sie die Anforderung eines neuen Passwortes.';
89
$wb['pw_error'] = 'Benutzername oder E-Mail Adresse stimmen nicht überein.';
910
$wb['pw_error_noinput'] = 'Bitte geben Sie Ihre E-Mail Adresse und Ihren Benutzernamen ein.';
1011
$wb['pw_reset_mail_msg'] = 'Das Passwort wurde zurückgesetzt. Das neue Passwort lautet: ';
11-
$wb['pw_reset_mail_title'] = 'Ihr Passwort wurde zurückgesetzt.';
12+
$wb['pw_reset_mail_title'] = 'Ihr Passwort wurde zurückgesetzt';
13+
$wb['pw_reset_act_mail_msg'] = 'Bitte bestätigen Sie die Anforderung eines neuen Passworts, indem Sie folgenden Link besuchen: ';
14+
$wb['pw_reset_act_mail_title'] = 'Anforderung zum Zurücksetzen des Passworts';
1215
$wb['user_regex_error'] = 'Benutzername beinhaltet nicht erlaubte Zeichen oder ist länger als 64 Zeichen.';
1316
$wb['pw_error_length'] = 'Die Passwortlänge ist < 1 oder > 64 Zeichen.';
1417
$wb['login_txt'] = 'Anmelden';
@@ -25,4 +28,7 @@ $wb['back_txt'] = 'Zur&uuml;ck';
2528
$wb['stay_logged_in_txt'] = 'Dauerhaft eingeloggt bleiben';
2629
$wb['email_error'] = 'Email contains unallowed characters or has a invalid format.';
2730
$wb['lost_password_function_disabled_txt'] = 'Die Passwort vergessen Funktion steht für diesen Benutzer nicht zur Verfügung.';
31+
$wb['lost_password_function_wait_txt'] = 'Sie können im Moment kein neues Passwort anfordern. Bitte warten Sie einige Minuten.';
32+
$wb['lost_password_function_expired_txt'] = 'Der Passwortlink ist abgelaufen. Bitte fordern Sie einen neuen an.';
33+
$wb['lost_password_function_denied_txt'] = 'Dieser Passwortlink ist ungültig.';
2834
?>

interface/web/login/lib/lang/en.lng

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ $wb['error_user_blocked'] = "User is blocked.";
55
$wb['error_user_too_many_logins'] = "To many wrong login's, Please retry it after 15 minutes";
66
$wb['pass_reset_txt'] = 'A new password will be generated and send to your email address if the email address entered below matches the email address in your client settings.';
77
$wb['pw_reset'] = 'The password has been reset and send to your email address.';
8+
$wb['pw_reset_act'] = 'You have been sent an activation link. Please visit the link to confirm your password request.';
89
$wb['pw_error'] = 'Username or email address does not match.';
910
$wb['pw_error_noinput'] = 'Please enter email address and username.';
1011
$wb['pw_reset_mail_msg'] = 'The password to your ISPConfig 3 control panel account has been reset. The new password is: ';
11-
$wb['pw_reset_mail_title'] = 'ISPConfig 3 Control panel password has been reset.';
12+
$wb['pw_reset_mail_title'] = 'ISPConfig 3 Control panel password has been reset';
13+
$wb['pw_reset_act_mail_title'] = 'Confirm ISPConfig 3 Control panel password reset';
14+
$wb['pw_reset_act_mail_msg'] = 'Please confirm that your want to reset your ISPConfig 3 control panel account password by visiting the following activation link: ';
1215
$wb['user_regex_error'] = 'Username contains unallowed characters or is longer than 64 characters.';
1316
$wb['pw_error_length'] = 'The password length is < 1 or > 64 characters.';
1417
$wb['email_error'] = 'Email contains unallowed characters or has a invalid format.';
@@ -25,4 +28,7 @@ $wb['error_maintenance_mode'] = 'This ISPConfig installation is currently under
2528
$wb['theme_not_compatible'] = 'The chosen theme is not compatible with the current ISPConfig version. Please check for a new version of the theme.<br />The default theme as been activated automatically.';
2629
$wb['stay_logged_in_txt'] = 'Keep me logged in';
2730
$wb['lost_password_function_disabled_txt'] = 'The lost password function is not available for this user.';
31+
$wb['lost_password_function_wait_txt'] = 'You cannot request a new password, yet. Please wait a few minutes.';
32+
$wb['lost_password_function_expired_txt'] = 'This activation link has expired. Please request a new one.';
33+
$wb['lost_password_function_denied_txt'] = 'This activation link is not valid.';
2834
?>

interface/web/login/password_reset.php

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,77 @@
4848
$continue = true;
4949

5050
if(isset($_POST['username']) && $_POST['username'] != '' && $_POST['email'] != '' && $_POST['username'] != 'admin') {
51-
5251
if(!preg_match("/^[\w\.\-\_]{1,64}$/", $_POST['username'])) {
5352
$app->tpl->setVar("error", $wb['user_regex_error']);
5453
$continue = false;
5554
}
56-
if(!preg_match("/^\w+[\w.-]*\w+@\w+[\w.-]*\w+\.[a-z]{2,10}$/i", $_POST['email'])) {
55+
if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
5756
$app->tpl->setVar("error", $wb['email_error']);
5857
$continue = false;
5958
}
6059

6160
$username = $_POST['username'];
6261
$email = $_POST['email'];
6362

64-
$client = $app->db->queryOneRecord("SELECT client.*, sys_user.lost_password_function FROM client,sys_user WHERE client.username = ? AND client.email = ? AND client.client_id = sys_user.client_id", $username, $email);
63+
$client = $app->db->queryOneRecord("SELECT client.*, sys_user.lost_password_function, sys_user.lost_password_hash, IF(sys_user.lost_password_reqtime IS NOT NULL AND DATE_SUB(NOW(), INTERVAL 15 MINUTE) < sys_user.lost_password_reqtime, 1, 0) as `lost_password_wait` FROM client,sys_user WHERE client.username = ? AND client.email = ? AND client.client_id = sys_user.client_id", $username, $email);
64+
65+
if($client['lost_password_function'] == 0) {
66+
$app->tpl->setVar("error", $wb['lost_password_function_disabled_txt']);
67+
} elseif($client['lost_password_wait'] == 1) {
68+
$app->tpl->setVar("error", $wb['lost_password_function_wait_txt']);
69+
} elseif ($continue) {
70+
if($client['client_id'] > 0) {
71+
$username = $client['username'];
72+
$password_hash = sha1(uniqid('ispc_pw'));
73+
$app->db->query("UPDATE sys_user SET lost_password_reqtime = NOW(), lost_password_hash = ? WHERE username = ?", $password_hash, $username);
74+
$app->tpl->setVar("message", $wb['pw_reset_act']);
75+
76+
$server_domain = (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : $_SERVER['HTTP_HOST']);
77+
if($server_domain == '_') {
78+
$tmp = explode(':',$_SERVER["HTTP_HOST"]);
79+
$server_domain = $tmp[0];
80+
unset($tmp);
81+
}
82+
if(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on') $server_domain = 'http://' . $server_domain;
83+
else $server_domain = 'https://' . $server_domain;
84+
85+
if(isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != '443') $server_domain .= ':' . $_SERVER['SERVER_PORT'];
86+
87+
$app->uses('getconf,ispcmail');
88+
$mail_config = $server_config_array['mail'];
89+
if($mail_config['smtp_enabled'] == 'y') {
90+
$mail_config['use_smtp'] = true;
91+
$app->ispcmail->setOptions($mail_config);
92+
}
93+
$app->ispcmail->setSender($mail_config['admin_mail'], $mail_config['admin_name']);
94+
$app->ispcmail->setSubject($wb['pw_reset_act_mail_title']);
95+
$app->ispcmail->setMailText($wb['pw_reset_act_mail_msg'].$server_domain . '/login/password_reset.php?username=' . urlencode($username) . '&hash=' . urlencode($password_hash));
96+
$app->ispcmail->send(array($client['contact_name'] => $client['email']));
97+
$app->ispcmail->finish();
98+
99+
$app->tpl->setVar("msg", $wb['pw_reset_act']);
100+
} else {
101+
$app->tpl->setVar("error", $wb['pw_error']);
102+
}
103+
}
104+
} elseif(isset($_GET['username']) && $_GET['username'] != '' && $_GET['hash'] != '') {
105+
106+
if(!preg_match("/^[\w\.\-\_]{1,64}$/", $_GET['username'])) {
107+
$app->tpl->setVar("error", $wb['user_regex_error']);
108+
$continue = false;
109+
}
110+
111+
$username = $_GET['username'];
112+
$hash = $_GET['hash'];
113+
114+
$client = $app->db->queryOneRecord("SELECT client.*, sys_user.lost_password_function, sys_user.lost_password_hash, IF(sys_user.lost_password_reqtime IS NULL OR DATE_SUB(NOW(), INTERVAL 1 DAY) > sys_user.lost_password_reqtime, 1, 0) as `lost_password_expired` FROM client,sys_user WHERE client.username = ? AND client.client_id = sys_user.client_id", $username);
65115

66116
if($client['lost_password_function'] == 0) {
67117
$app->tpl->setVar("error", $wb['lost_password_function_disabled_txt']);
118+
} elseif($client['lost_password_expired'] == 1) {
119+
$app->tpl->setVar("error", $wb['lost_password_function_expired_txt']);
120+
} elseif($client['lost_password_hash'] != $hash) {
121+
$app->tpl->setVar("error", $wb['lost_password_function_denied_txt']);
68122
} elseif ($continue) {
69123
if($client['client_id'] > 0) {
70124
$server_config_array = $app->getconf->get_global_config();
@@ -75,7 +129,7 @@
75129
$new_password_encrypted = $app->auth->crypt_password($new_password);
76130

77131
$username = $client['username'];
78-
$app->db->query("UPDATE sys_user SET passwort = ? WHERE username = ?", $new_password_encrypted, $username);
132+
$app->db->query("UPDATE sys_user SET passwort = ?, lost_password_hash = '', lost_password_reqtime = NULL WHERE username = ?", $new_password_encrypted, $username);
79133
$app->db->query("UPDATE client SET password = ? WHERE username = ?", $new_password_encrypted, $username);
80134
$app->tpl->setVar("message", $wb['pw_reset']);
81135

0 commit comments

Comments
 (0)