This repository has been archived by the owner on Aug 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
login.php
88 lines (81 loc) · 2.95 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
<?php
/*
* @author: Scottish Borders Design
* @script: SBD SHOUTcast Manager
* @function: Login
* @website: http://scottishbordersdesign.co.uk/
*/
ob_start();
session_start();
if (file_exists("install/install.php")) {
header('Location: install/install.php');
exit;
}
require('include/functions.inc.php');
$db = dbConnect();
$config = settings();
$_LANG = _LANG();
$smarty->assign("lang", $_LANG);
checkSSL();
if (isset($_SESSION['username'])) {
$db->where("username", $_SESSION['username']);
}
$userExsists = $db->getOne("members");
if (isset($_SESSION['username']) && $db->count > 0) {
header('Location: home.php');
} else {
if (isset($_POST['2stepusername']) && isset($_POST['verifycode'])) {
// do the 2 Step check!
include ('include/GoogleAuthenticator.php');
$authenticator = new PHPGangsta_GoogleAuthenticator();
$verifyCode = $_POST['verifycode'];
$db->where("username", $_POST['2stepusername']);
$member = $db->getOne("members");
$secret = $member['2stepauth'];
$tolerance = 1;
$checkResult = $authenticator->verifyCode($secret, $verifyCode, $tolerance);
if ($checkResult) {
$_SESSION["ip"] = getenv('REMOTE_ADDR');
$_SESSION["username"] = $_POST['2stepusername'];
addevent($_POST['2stepusername'], "logged in from " . getenv('REMOTE_ADDR') . " using 2 Step Authentication");
header('Location: ' . $config['web_addr'] . '/home.php');
} else {
$error = "2 Step authentication failed, please try again.";
}
}
if (isset($_REQUEST['Submit'])) {
if (!$_POST['username'] || !$_POST['password']) {
$error = $_LANG['loginerror']['allfields'];
} else {
if (login_check($_POST['username'], $_POST['password'])) {
if (google_auth_part_check($_POST['username'])) {
header('Location: ' . $config['web_addr'] . '/home.php');
$_SESSION["ip"] = getenv('REMOTE_ADDR');
$_SESSION["username"] = $_POST['username'];
addevent($_POST['username'], "logged in from " . getenv('REMOTE_ADDR'));
} else {
// we have 2 Step!
$smarty->assign("2stepcheck", TRUE);
$smarty->assign("2stepusername", $_POST['username']);
}
} else {
$error = $_LANG['loginerror']['invalid'];
}
}
} else {
if (isset($_GET['logout'])) {
session_destroy();
$error = $_LANG['loginerror']['sessionerror'];
echo form($error);
} else {
if (!isset($_SESSION['username']) && !isset($_POST['verifycode'])) {
$error = $_LANG['loginerror']['welcome2'];
}
}
}
if (isset($error)) {
$smarty->assign("error", $error);
}
$smarty->display('login.tpl');
}
?>