-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqrcode.php
More file actions
182 lines (142 loc) · 5.01 KB
/
qrcode.php
File metadata and controls
182 lines (142 loc) · 5.01 KB
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
<?php
/*
Author: YChi Lu
Github ogiginal Author: Iszuddin Ismail
POC only based on others effort,
Testing out implementation of Google Authenticator for login. This demo uses Google Authenticator library from PHPGangsta
https://github.com/PHPGangsta/GoogleAuthenticator
*/
require_once 'gauth.php';
require_once 'tes.php';
$ga = new GoogAuth();
$email = (isset($_REQUEST['email'])) ? strtolower(trim($_REQUEST['email'])) : false;
$code = (isset($_REQUEST['code'])) ? strtolower(trim($_REQUEST['code'])) : false;
$action = (isset($_REQUEST['action'])) ? strtolower(trim($_REQUEST['action'])) : '' ;
$app_name = "DogCU";
// part3 -- test the code againsts Google Authenticator
if ($action == 'auth') {
if (!file_exists(md5($email))) { show_error("unknown account"); }
if (!$code) { show_error("code cannot be empty"); }
$secret_key = file_get_contents(md5($email));
$checkResult = $ga->verifyCode($secret_key, $code, 2); // 2 = 2*30sec clock tolerance
$response['code'] = 1;
$response['status'] = $api_response_code[ $response['code'] ]['HTTP Response'];
if ($checkResult) {
$response['data']= true;
$response['member'] = $email;
$response['msg'] = "AuthResult";
$response['AuthResult'] = true;
deliver_response('json', $response);
} else {
$account = $app_name.'-'.$email;
$qrCodeUrl = $ga->getQRCodeGoogleUrl($account, $secret_key);
$response['data']= true;
$response['member'] = $email;
$response['msg'] = "AuthResult";
$response['AuthResult'] = false;
$response['key'] = $secret_key;
$response['account'] = $account;
$response['url'] = $qrCodeUrl;
deliver_response('json', $response);
// show_error("Wrong code. Please try again.".$secret_key);
}
// if registered, request for code, if not, register user
} elseif ($action == 'check') {
//echo $email;
if ($email ) {
$response['code'] = 1;
$response['status'] = $api_response_code[ $response['code'] ]['HTTP Response'];
if (file_exists(md5($email))) { // registered in the past
$response['data']= true;
$response['member'] = $email;
$response['msg'] = 'check';
deliver_response('json', $response);
/*
echo $_REQUEST['action'];
echo "<br>Enter the code for $app_name from Google Authenticator<br>";
echo "<form action='qrcode.php?action=part3' method='post'>";
echo "<input type='text' name='email' value='$email' readonly /><br />";
echo "<input type='text' name='code' /><br />";
echo "<button type='submit'>SUBMIT</button>";
echo "</form>";*/
} else {
$response['data']= false;
$response['member'] = $email;
$response['msg'] = 'check';
deliver_response('json', $response);
// new registration
}
} else {
show_error("invalid verb or parameters");
}
}
elseif ($action == 'create')
{
$response['code'] = 1;
$response['status'] = $api_response_code[ $response['code'] ]['HTTP Response'];
if ($email )
{
$response['email'] = $email;
$response['data']= true;
$secret_key = $ga->createSecret();
$account = $app_name.'-'.$email;
file_put_contents(md5($email), $secret_key);
$qrCodeUrl = $ga->getQRCodeGoogleUrl($account, $secret_key);
$response['data']= true;
$response['member'] = $email;
$response['msg'] = "new";
$response['key'] = $secret_key;
$response['account'] = $account;
$response['url'] = $qrCodeUrl;
deliver_response('json', $response);
}
else
{
$response['data']= false;
}
deliver_response('json', $response);
}
elseif ($action == 'delete')
{
$response['code'] = 1;
$response['status'] = $api_response_code[ $response['code'] ]['HTTP Response'];
$response['member'] = $email;
if (file_exists(md5($email))) { // registered in the past
unlink(md5($email));
$response['data']= true;
$response['msg'] = 'delete_done';
}
else
{
$response['data']= false;
$response['msg'] = 'file_not_exist';
}
deliver_response('json', $response);
}
else {
if( strcasecmp($_GET['method'],'hello') == 0){
$response['code'] = 1;
$response['status'] = $api_response_code[ $response['code'] ]['HTTP Response'];
$response['data'] = 'Hello World';
}
// --- Step 4: Deliver Response
// Return Response to browser
//$friendid = isset($_GET['friendid']) ? $_GET['friendid'] : 'empty';
/*if (isset($_GET['format']))
{
deliver_response($_GET['format'], $response);
}
else
{
deliver_response('json', $response);
}*/
echo "L-95 Enter email address to proceed with login.";
echo "<form action='". $_SERVER['PHP_SELF']."?action=check&format=json' method='POST'>";
echo "<input type='text' name='email' value='' />";
echo "<button type='submit'>LOGIN</button>";
echo "</form>";
}
function show_error($errmessage){
echo $errmessage.'<br/>';
echo '<a href="qrcode.php">Got Back Home</a>';
}