/
login.php
executable file
·510 lines (459 loc) · 16.9 KB
/
login.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
<?php
/*
JM-booking
Copyright (C) 2007-2010 Jaermuseet <http://www.jaermuseet.no>
Contact: <hn@jaermuseet.no>
Project: <http://github.com/hnJaermuseet/JM-booking>
Based on ARBS, Advanced Resource Booking System, copyright (C) 2005-2007
ITMC der TU Dortmund <http://sourceforge.net/projects/arbs/>. ARBS is based
on MRBS by Daniel Gardner <http://mrbs.sourceforge.net/>.
This program 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.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*
JM-booking - login
*/
include 'glob_inc.inc.php';
$deactivated = false;
$external_failed = false; $complex_failed = false; $age_failed = false;
$is_external = isExternal();
if(isset($_POST['WEBAUTH_USER']))
{
$user = getUserName();
$pass = getUserPassword();
// Check if we do not have a username/password
if(empty($user) || empty($pass)) {
}
else
{
$user = slashes(htmlspecialchars(strip_tags($user),ENT_QUOTES)); // Username
$pass = getPasswordHash ($pass);
// Checking against database
$Q_login = db()->prepare("select user_id, deactivated, user_password_complex, user_password_lastchanged from `users` where user_name_short = :user_name_short and user_password = :user_password limit 1");
$Q_login->bindValue(':user_name_short', $user, PDO::PARAM_STR);
$Q_login->bindValue(':user_password', $pass, PDO::PARAM_STR);
$Q_login->execute();
if($Q_login->rowCount() > 0)
{
$loginInfo = $Q_login->fetch();
if($is_external)
{
try {
$user_login = array('user_password_lastchanged' => $loginInfo['user_password_lastchanged']);
loginPWcheckAge($user_login);
}
catch (Exception $e) {
$external_failed = true;
$age_failed = true;
}
}
if($loginInfo['deactivated'])
{
$deactivated = true;
}
elseif($is_external && !$loginInfo['user_password_complex'])
{
$external_failed = true;
$complex_failed = true;
}
elseif(!$external_failed)
{
$_SESSION['WEBAUTH_VALID']=true;
$_SESSION['WEBAUTH_USER']=$user;
$_SESSION['WEBAUTH_PW']=$pass;
// New variabels (JM-booking)
$_SESSION['user_id'] = $loginInfo['user_id'];
$_SESSION['user_password'] = $pass;
if(isset($_POST['redirect'])) {
header('Location: ' . $_POST['redirect']);
}
else {
header('Location: index.php');
}
exit();
}
}
else
{
}
}
}
if(isLoggedIn())
{
echo __('You\'re already logged in.').'<br><br>';
echo '<a href="logout.php">'.__('Log out').'</a>';
exit();
}
else
{
if(isset($_POST['WEBAUTH_USER'])) {
$user = slashes(htmlspecialchars(strip_tags($_POST['WEBAUTH_USER']), ENT_QUOTES));
}
else {
$user = '';
}
$forgot_pw_failed = false;
$forgot_pw_found = false;
$forgot_pw_keyfound = false;
$forgot_pw_keyokey = false;
$forgot_pw_user = '';
if(isset($_GET['forgot_pw_user'])) {
$forgot_pw_user = $_GET['forgot_pw_user'];
}
if(isset($_POST['forgot_pw_user'])) {
$forgot_pw_user = $_POST['forgot_pw_user'];
}
if(isset($_GET['forgot_pw']) && $_GET['forgot_pw'] == '1' && $forgot_pw_user != '')
{
// Forgot password
$user = slashes(htmlspecialchars(strip_tags($forgot_pw_user),ENT_QUOTES)); // Username
$Q_login = db()->prepare("
select user_id, deactivated, user_newpassword_key, user_newpassword_validto from `users` where
deactivated = '0' and
(
user_name_short = :username ||
user_email = :username
)
limit 1");
$Q_login->bindValue(':username', $user);
$Q_login->execute();
if($Q_login->rowCount() > 0)
{
$row = $Q_login->fetch();
$user_id = $row['user_id'];
$forgot_pw_found = true;
if(isset($_GET['key']))
{
$forgot_pw_keyfound = true;
$newpw_failed_msg = ''; $newpw_pw = ''; $newpw_failed = false;
$newpw_user = getUser($user_id);
$newpw_key = slashes(htmlspecialchars(strip_tags($_GET['key']),ENT_QUOTES));
if(!count($newpw_user)) { echo 'Systemfeil. Arg... Sorry :-('; exit; }
if(
$newpw_key == $row['user_newpassword_key'] &&
$row['user_newpassword_validto'] >= time()
)
{
$forgot_pw_keyokey = true;
if(!isset($_POST['password_new']))
{
// Extend life time of key
$valid_to = time()+ 60*15; // 15 min
db()
->prepare("
update `users`
set
user_newpassword_validto = '$valid_to'
where
user_id = '$user_id'")
->execute();
}
else
{
// Setting the new password
$newpw_user['user_password_lastchanged'] = time(); // All new
$newpw_pw = $_POST['password_new'];
try {
loginPWcheckExternal ($newpw_user, $newpw_pw);
loginPWcheckSetNew ($newpw_user, $newpw_pw);
}
catch (Exception $e)
{
$newpw_failed_msg = $e->getMessage();
$newpw_failed = true;
}
if(
!$newpw_failed ||
($newpw_failed && isset($_POST['ignore_msg']) && $_POST['ignore_msg'] == '1')
)
{
$sql =
'UPDATE `users` SET '.
'`user_password` = \''.getPasswordHash($newpw_pw).'\', '.
'`user_password_1` = \''.$newpw_user['user_password'].'\', '.
'`user_password_2` = \''.$newpw_user['user_password_1'].'\', '.
'`user_password_3` = \''.$newpw_user['user_password_2'].'\', '.
'`user_password_lastchanged` = \''.time().'\', '.
'`user_newpassword_validto` = \'\', '.
'`user_password_complex` = \''.!$newpw_failed.'\''.
' WHERE `user_id` = '.$newpw_user['user_id'].' LIMIT 1 ;';
db()->prepare($sql)->execute();
header('Location: logout.php?newpw_ok=1');
exit;
}
}
}
}
else
{
// Generate key and valid_to
$key = sha1(microtime(true).mt_rand(10000,90000));
$valid_to = time()+ 60*15; // 15 min
db()
->prepare("
update `users`
set
user_newpassword_key = '$key',
user_newpassword_validto = '$valid_to'
where
user_id = '$user_id'")
->execute();
$smarty = new Smarty;
templateAssignSystemvars('smarty');
$smarty->assign('forgot_pw_user', $user);
$smarty->assign('key', $key);
$smarty->assign('valid_to', $valid_to);
$message = $smarty->fetch('file:mail-forgot_pw.tpl');
$subject = 'Glemt passord - J&aerligmuseets bookingsystem';
emailSend($user_id, $subject, $message);
}
}
else
{
$forgot_pw_failed = true;
}
}
echo '<html>'.chr(10).'<head>'.chr(10).
' <title>'.__('JM-booking').' - '.__('Log in').'</title>'.chr(10).
' <link rel="stylesheet" href="css/jm-booking.css" type="text/css">'.chr(10).
' <meta http-equiv="Content-Type" content="text/html; charset=utf8">'.chr(10).
' <script type="text/javascript" src="js/browser_detection.js"></script>'.chr(10).
'</head>'.chr(10).
'<body>'.chr(10);
echo '<br><br><br><br>'.chr(10).chr(10);
echo $testSystem['msgLogin'];
echo
'<table '.
'style="border:0px solid #0000ff; border-collapse:collapse;" '.
'align="center" '.
'cellspacing="0" '.
'cellpadding="0">'.chr(10);
' <tr>'.chr(10);
if($forgot_pw_keyfound)
echo ' <td align="center" style="border:1px solid #0000ff; padding: 30px; width: 600px;" colspan="2">'.chr(10);
else
echo ' <td align="center" style="border:1px solid #0000ff; padding: 30px; width: 300px;">'.chr(10);
if(!$forgot_pw_keyfound && isset($_GET['forgot_pw']) && $_GET['forgot_pw'] == '1')
{
echo ' <form method="POST" action="'.$_SERVER['PHP_SELF'].'?forgot_pw=1">'.chr(10);
if(isset($_GET['redirect']))
echo '<input type="hidden" name="redirect" value="'.$_GET['redirect'].'">'.chr(10);
echo chr(10).
'<table width="300" border="0" align="center" cellspacing="0" cellpadding="1">'.chr(10).
' <tr>'.chr(10).
' <td colspan="2" style="font-size:14px; padding: 10px;">'.
'<b>Typisk å glemme passordet,<br />skal hjelpe deg jeg...</b></td>'.chr(10).
' </tr>'.chr(10).chr(10);
echo
' <tr>'.chr(10).
' <td colspan="2">'.
'Trenger å vite brukernavnet ditt eller eposten din. Skal så sende deg en kode på epost, '.
'så skal du få lage nytt passord.<br /><br /></td>'.chr(10).
' </tr>'.chr(10).chr(10);
if($forgot_pw_failed) {
echo ' <tr><td colspan="2" align="center"><div class="error">'.
'<b>'._h('Did not find any user with that username or with that email address.').'</b><br /><br />'.
_h('Please try again.').
'</div></td></tr>'.chr(10).chr(10);
}
echo ' <tr>'.chr(10).
' <td>'.__('Username').' /<br />'._h('E-mail').'</td>'.chr(10).
' <td><input id="dofocus" type="text" value="'.$user.'" name="forgot_pw_user"></td>'.chr(10).
' </tr>'.chr(10).chr(10);
echo ' <tr>'.chr(10).
' <td> </td>'.chr(10).
' <td><input type="submit" value="'._h('Send e-mail with code').'"></td>'.chr(10).
' </tr>'.chr(10).chr(10);
echo '</table>'.chr(10).chr(10);
echo ' </form>'.chr(10);
echo '<br /><br />';
}
elseif($forgot_pw_keyfound)
{
if(!$forgot_pw_keyokey)
{
echo '<div class="error">'.
'Koden du oppgav er for gammel (mer enn 15 minutter gammel), '.
'eller eksisterer ikke for brukeren.<br /><br />'.
'Sjekk også at du ikke har fått en ny etter den du trykket på nå.<br /><br />'.
'Hvis du ikke får det til, '.
'så <a href="'.$_SERVER['PHP_SELF'].'?forgot_pw=1">få tilsendt en ny</a>.'.
'</div>';
}
else
{ // start new pw form
echo '<h1>'._h('Change password for').' '.$newpw_user['user_name'].'</h1>'.chr(10).chr(10);
echo '<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>';
if(isset($_GET['ok']) && $_GET['ok'] == '1')
{
echo '<div class="success" style="width: 400px;">'._h('Password has been changed.').'</div>';
}
else
{
echo 'For ekstern pålogging (ikke Jæmuseets maskiner),<br />'.
'så kreves det at passordet inneholder store og små bokstaver samt tall.<br />';
echo '<form action="'.$_SERVER['PHP_SELF'].'?forgot_pw=1&forgot_pw_user='.$user.'&key='.$newpw_key.'" method="post">'.chr(10);
echo '<b>'._h('New password').':</b><br />'.chr(10);
echo '<input type="password" id="dofocus" name="password_new" value="'.$newpw_pw.'"><br /><br />'.chr(10).chr(10);
if(!isset($_POST['password_new']))
{
echo '<input type="submit" value="'._h('Save password').'">'.chr(10);
}
elseif($newpw_failed)
{
echo '<script type="text/javascript">
$("input[type=password][name=password_new]").keyup(function() {
$("#failed_msg").slideUp();
$("input[type=hidden][name=ignore_msg]").attr("value", "0");
});
$("input[type=password][name=password_new]").change(function() {
$("#failed_msg").slideUp();
$("input[type=hidden][name=ignore_msg]").attr("value", "0");
});
$("input[type=password][name=password_new]").click(function() {
$("#failed_msg").slideUp();
$("input[type=hidden][name=ignore_msg]").attr("value", "0");
});
</script>'.chr(10);
echo '<div class="notice" id="failed_msg" style="width: 400px;">'.
_h(
'Password can not be used if you want to be able to log in externally. '.
'Log in from internal computers will still be possible.'
).'<br /><br />'.
'<b>- '.$newpw_failed_msg.'</b><br /><br />'.
_h('Press "Save password" again to use the choosen password.').
'<br />'.
'Du kan fint ha dette passordet hvis du bare vil logge på fra J&aerligmuseets maskiner'.
'</div>';
echo '<input type="hidden" value="1" name="ignore_msg">';
echo '<input type="submit" value="'._h('Save password').'">'.chr(10);
}
/*
elseif($failed_msg != '')
{
echo '<div class="success" style="width: 400px;">'.
_h('The password is good enougth for external logins.').'</div>';
echo '<input type="submit" value="'._h('Save password').'">'.chr(10);
}*/
echo '</form>'.chr(10);
}
} // end new pw form
}
else
{ // start login form
echo ' <form method="POST" action="'.$_SERVER['PHP_SELF'].'">'.chr(10);
if(isset($_GET['redirect']))
echo '<input type="hidden" name="redirect" value="'.$_GET['redirect'].'">'.chr(10);
echo chr(10).
'<table width="300" border="0" align="center" cellspacing="0" cellpadding="1">'.chr(10).
' <tr>'.chr(10).
' <td colspan="2" style="text-align:center; font-size:18px; padding: 10px;"><b>Innlogging til booking</b></td>'.chr(10).
' </tr>'.chr(10).chr(10);
if(isset($_GET['newpw_ok']) && $_GET['newpw_ok'] == '1')
{
echo ' <tr><td colspan="2" align="center"><div class="success" style="width: 400px;">'.
'<b>'._h('Your password has been changed.').'</b><br /><br />'.
_h('Please log in again.').
'</div></td></tr>'.chr(10).chr(10);
}
if($deactivated) {
echo ' <tr><td colspan="2" align="center"><div class="error error-1">'.
__('The account is disabled').
'</div></td></tr>'.chr(10).chr(10);
}
elseif($external_failed && $complex_failed) {
echo ' <tr><td colspan="2" align="center"><div class="error error-2">'.
_h('You do not have access to the system because your password is not complex enough for external login.').' '.
_h(
'Please get yourself a new password or use an internal computer instead. '.
'Your password will still work when using internal computers.'
).
'</div></td></tr>'.chr(10).chr(10);
}
elseif($external_failed && $age_failed) {
echo ' <tr><td colspan="2" align="center"><div class="error error-3">'.
_h('You do not have access to the system because your password is too old for external login.').' '.
_h(
'Please get yourself a new password the next time you are using an internal computer. '.
'Your password will still work when using internal computers.'
).
'</div></td></tr>'.chr(10).chr(10);
}
elseif(isset($_POST['WEBAUTH_USER'])) {
echo ' <tr><td colspan="2"" align="center"><div class="error">'.
__('Username and/or password is wrong').
'</div></td></tr>'.chr(10).chr(10);
}
echo ' <tr>'.chr(10).
' <td>'.__('Username').'</td>'.chr(10).
' <td><input id="dofocus" type="text" value="'.$user.'" name="WEBAUTH_USER"></td>'.chr(10).
' </tr>'.chr(10).chr(10);
echo ' <tr>'.chr(10).
' <td>'.__('Password').'</td>'.chr(10).
' <td><input id="dofocus2" type="password" name="WEBAUTH_PW"></td>'.chr(10).
' </tr>'.chr(10).chr(10);
echo ' <tr>'.chr(10).
' <td> </td>'.chr(10).
' <td><input type="submit" value="'.__('Log in').'"></td>'.chr(10).
' </tr>'.chr(10).chr(10);
echo '</table>'.chr(10).chr(10);
echo ' </form>'.chr(10);
echo '<br /><br />';
echo '<a href="'.$_SERVER['PHP_SELF'].'?forgot_pw=1">'._h('Forgot password').'?</a>';
} // End login form
if(!$forgot_pw_keyfound)
{
echo ' </td>'.chr(10);
echo
' <td style="text-align: center; vertical-align:middle; border:1px solid #0000ff; padding: 30px; width: 300px;">'.chr(10);
if(isset($_GET['forgot_pw']) && $_GET['forgot_pw'] == '1')
{
if(!$forgot_pw_found)
echo ' ';
else
{
echo '<div class="success"><b>Supert!<br />Nå: Trykk på lenken i e-posten</b><br />'.
'En e-post er sendt til deg med en lenke du må trykke på. '.
'Når du går inn på denne lenken, så vil du få muligheten til å bytte passord.</div>';
}
}
else
{
echo
' <a href="/wiki/" style="font-size: 28px">Wiki</a><br>'.chr(10).
' Wiki for opplæring og rutiner på Vitenfabrikken'.chr(10);
}
}
echo
' </td>'.chr(10).
' </tr>'.chr(10).
'</table>'.chr(10).chr(10);
if(!(isset($_GET['forgot_pw']) && $_GET['forgot_pw'] == '1'))
{
if(isset($_POST['WEBAUTH_USER']))
echo '<script language="javascript">document.getElementById(\'dofocus2\').focus();</script>';
else
echo '<script language="javascript">document.getElementById(\'dofocus\').focus();</script>';
}
echo chr(10).
'</body>'.chr(10).
'</html>';
if($is_external)
{
echo '<!-- External -->';
}
else
{
echo '<!-- Internal -->';
}
exit();
}