-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphpBB.java
203 lines (187 loc) · 5.89 KB
/
phpBB.java
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
/**************************************************************************
* This file is part of MCbb.
* MCbb 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 3 of the License, or
* (at your option) any later version.
* MCbb 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 MCbb. If not, see <http://www.gnu.org/licenses/>.
*************************************************************************/
import java.sql.ResultSet;
import java.sql.SQLException;
import de.javakara.manf.software.Software;
import de.javakara.manf.software.User;
import de.javakara.manf.util.EncryptionManager;
public class phpBB extends Software {
@Override
public String getForumGroup(User user) {
try {
int userId = user.getId();
if (userId != 0) {
ResultSet rs = database
.executeQuery("SELECT group_id FROM "
+ this.config.getString("mysql.prefix")
+ "user_group WHERE user_id ='"
+ userId
+ "' ORDER BY group_leader DESC,user_pending ASC, group_id DESC");
if (rs.next()) {
int groupId = rs.getInt("group_id");
rs = database.executeQuery("SELECT servergroup FROM "
+ this.config.getString("mysql.prefix")
+ "groups WHERE group_id ='" + groupId + "'");
user.setGroupId(groupId);
if (rs.next()) {
return rs.getString("servergroup");
}
}
} else {
System.out.println("[MCbb] Sorry... Theres a fail in there!");
}
} catch (SQLException e) {
System.out.println("ForumUserError: " + e.toString());
}
System.out.println("User Forum Group not recognised!");
return null;
}
@Override
public int getNewPosts() {
return 0;
}
@Override
protected boolean isRegisteredOld(User user) {
try {
ResultSet rs = database.executeQuery("SELECT user_id,username_clean,user_type FROM "
+ this.config.getString("mysql.prefix")
+ "users WHERE username_clean='"
+ user.getName()
+ "' LIMIT 1");
if (rs.next()) {
int id = rs.getInt("user_id");
int type = rs.getInt("user_type");
user.setUserId(id);
user.setUserType(type);
return (type != 1);
}
} catch (SQLException e) {
System.out.println("Qwertzy2");
e.printStackTrace();
}
return false;
}
@Override
protected boolean isCustomFieldRegistered(User user) {
try {
String name = user.getName();
ResultSet rs = database.executeQuery("SELECT user_id FROM "
+ this.config.getString("mysql.prefix")
+ "profile_fields_data WHERE pf_"
+ getFieldName(Integer.parseInt(this.config
.getString("field.id"))) + "='" + name
+ "' LIMIT 1");
if (rs.next()) {
int id = rs.getInt("user_id");
user.setUserId(id);
rs = database
.executeQuery("SELECT username_clean,user_type FROM "
+ this.config.getString("mysql.prefix")
+ "users WHERE user_id='" + id
+ "' LIMIT 1");
if (rs.next()) {
int type = rs.getInt("user_type");
user.setUserType(type);
return (type != 1);
}
}
} catch (SQLException e) {
e.printStackTrace();
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return false;
}
private String getFieldName(int id) throws ClassNotFoundException,
SQLException {
ResultSet rs = database.executeQuery("SELECT field_name FROM "
+ this.config.getString("mysql.prefix")
+ "profile_fields WHERE field_id='" + id + "' LIMIT 1");
if (rs.next()) {
return rs.getString("field_name");
}
return null;
}
@Override
public boolean isPasswordCorrect(User user,String password) {
try {
ResultSet rs;
String name = user.getName();
switch (authType) {
case 0:
rs = database.executeQuery("SELECT user_password,user_form_salt FROM "
+ this.config.getString("mysql.prefix")
+ "users WHERE username_clean='"
+ name + "' LIMIT 1");
break;
case 1:
int id = user.getId();
if(id == 0){
rs = database.executeQuery("SELECT user_id FROM "
+ this.config.getString("mysql.prefix")
+ "profile_fields_data WHERE pf_"
+ getFieldName(Integer.parseInt(this.config
.getString("field.id"))) + "='" + name
+ "' LIMIT 1");
if (rs.next()) {
id = rs.getInt("user_id");
}
}
rs = database.executeQuery("SELECT user_password FROM "
+ this.config.getString("mysql.prefix")
+ "users WHERE user_id='"
+ id
+ "' LIMIT 1");
break;
default:
return false;
}
if (rs.next()) {
String realpassword = rs.getString("user_password");
if (phpbb_check_hash(password,realpassword)) {
return true;
}
}
} catch (SQLException e) {
e.printStackTrace();
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return false;
}
/***
* Port of phpBB3 password handling to Java.
* See phpBB3/includes/functions.php
* just used phpbb_check_hash and its sub
* http://larsho.blogspot.de/2008/02/passwords-in-phpbb-3.html
* @author lars
* @param password
* @param hash
* @return
*/
public boolean phpbb_check_hash(String password, String hash) {
if (hash.length() == 34)
return EncryptionManager._hash_crypt_private(password, hash).equals(hash);
else
return EncryptionManager.md5(password).equals(hash);
}
@Override
protected String getName() {
return "phpBB";
}
}