-
Notifications
You must be signed in to change notification settings - Fork 0
/
Login_jsp.java
613 lines (528 loc) · 20.9 KB
/
Login_jsp.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
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
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import org.apache.jasper.runtime.*;
public class Login_jsp extends HttpJspBase {
//
// Filename: Common.jsp
// Generated with CodeCharge v.1.2.0
// JSP.ccp build 05/21/2001
//
static final String CRLF = "\r\n";
static final int UNDEFINT=Integer.MIN_VALUE;
static final int adText = 1;
static final int adDate = 2;
static final int adNumber = 3;
static final int adSearch_ = 4;
static final int ad_Search_ = 5;
static final String appPath ="/";
//Database connection string
static final String DBDriver ="";
static final String strConn ="";
static final String DBusername="";
static final String DBpassword="";
public static String loadDriver () {
String sErr = "";
try {
java.sql.DriverManager.registerDriver((java.sql.Driver)(Class.forName(DBDriver).newInstance()));
}
catch (Exception e) {
sErr = e.toString();
}
return (sErr);
}
public static void absolute(java.sql.ResultSet rs, int row) throws java.sql.SQLException{
for(int x=1;x<row;x++) rs.next();
}
java.sql.ResultSet openrs(java.sql.Statement stat, String sql) throws java.sql.SQLException {
java.sql.ResultSet rs = stat.executeQuery(sql);
return (rs);
}
String dLookUp(java.sql.Statement stat, String table, String fName, String where) {
java.sql.Connection conn1 = null;
java.sql.Statement stat1 = null;
try {
conn1 = cn();
stat1 = conn1.createStatement();
java.sql.ResultSet rsLookUp = openrs( stat1, "SELECT " + fName + " FROM " + table + " WHERE " + where);
if (! rsLookUp.next()) {
rsLookUp.close();
stat1.close();
conn1.close();
return "";
}
String res = rsLookUp.getString(1);
rsLookUp.close();
stat1.close();
conn1.close();
return (res == null ? "" : res);
}
catch (Exception e) {
return "";
}
}
long dCountRec(java.sql.Statement stat, String table, String sWhere) {
long lNumRecs = 0;
try {
java.sql.ResultSet rs = stat.executeQuery("select count(*) from " + table + " where " + sWhere);
if ( rs != null && rs.next() ) {
lNumRecs = rs.getLong(1);
}
rs.close();
}
catch (Exception e ) {};
return lNumRecs;
}
String proceedError(javax.servlet.http.HttpServletResponse response, Exception e) {
return e.toString();
}
String[] getFieldsName ( java.sql.ResultSet rs ) throws java.sql.SQLException {
java.sql.ResultSetMetaData metaData = rs.getMetaData();
int count = metaData.getColumnCount();
String[] aFields = new String[count];
for(int j = 0; j < count; j++) {
aFields[j] = metaData.getColumnLabel(j+1);
}
return aFields;
}
java.util.Hashtable getRecordToHash ( java.sql.ResultSet rs, java.util.Hashtable rsHash, String[] aFields ) throws java.sql.SQLException {
for ( int iF = 0; iF < aFields.length; iF++ ) {
rsHash.put( aFields[iF], getValue(rs, aFields[iF]));
}
return rsHash;
}
java.sql.Connection cn() throws java.sql.SQLException {
return java.sql.DriverManager.getConnection(strConn , DBusername, DBpassword);
}
String toURL(String strValue){
if ( strValue == null ) return "";
if ( strValue.compareTo("") == 0 ) return "";
return java.net.URLEncoder.encode(strValue);
}
String toHTML(String value) {
if ( value == null ) return "";
value = replace(value, "&", "&");
value = replace(value, "<", "<");
value = replace(value, ">", ">");
value = replace(value, "\"", "&" + "quot;");
return value;
}
String getValueHTML(java.sql.ResultSet rs, String fieldName) {
try {
String value = rs.getString(fieldName);
if (value != null) {
return toHTML(value);
}
}
catch (java.sql.SQLException sqle) {}
return "";
}
String getValue(java.sql.ResultSet rs, String strFieldName) {
if ((rs==null) ||(isEmpty(strFieldName)) || ("".equals(strFieldName))) return "";
try {
String sValue = rs.getString(strFieldName);
if ( sValue == null ) sValue = "";
return sValue;
}
catch (Exception e) {
return "";
}
}
String getParam(javax.servlet.http.HttpServletRequest req, String paramName) {
String param = req.getParameter(paramName);
if ( param == null || param.equals("") ) return "";
param = replace(param,"&","&");
param = replace(param,"<","<");
param = replace(param,">",">");
param = replace(param,"&lt;","<");
param = replace(param,"&gt;",">");
return param;
}
boolean isNumber (String param) {
boolean result;
if ( param == null || param.equals("")) return true;
param=param.replace('d','_').replace('f','_');
try {
Double dbl = new Double(param);
result = true;
}
catch (NumberFormatException nfe) {
result = false;
}
return result;
}
boolean isEmpty (int val){
return val==UNDEFINT;
}
boolean isEmpty (String val){
return (val==null || val.equals("")||val.equals(Integer.toString(UNDEFINT)));
}
String getCheckBoxValue (String val, String checkVal, String uncheckVal, int ctype) {
if (val==null || val.equals("") ) return toSQL(uncheckVal, ctype);
else return toSQL(checkVal, ctype);
}
String toWhereSQL(String fieldName, String fieldVal, int type) {
String res = "";
switch(type) {
case adText:
if (! "".equals(fieldVal)) {
res = " " + fieldName + " like '%" + fieldVal + "%'";
}
case adNumber:
res = " " + fieldName + " = " + fieldVal + " ";
case adDate:
res = " " + fieldName + " = '" + fieldVal + "' ";
default:
res = " " + fieldName + " = '" + fieldVal + "' ";
}
return res;
}
String toSQL(String value, int type) {
if ( value == null ) return "Null";
String param = value;
if ("".equals(param) && (type == adText || type == adDate) ) {
return "Null";
}
switch (type) {
case adText: {
param = replace(param, "'", "''");
param = replace(param, "&", "&");
param = "'" + param + "'";
break;
}
case adSearch_:
case ad_Search_: {
param = replace(param, "'", "''");
break;
}
case adNumber: {
try {
if (! isNumber(value) || "".equals(param)) param="null";
else param = value;
}
catch (NumberFormatException nfe) {
param = "null";
}
break;
}
case adDate: {
param = "'" + param + "'";
break;
}
}
return param;
}
private String replace(String str, String pattern, String replace) {
if (replace == null) {
replace = "";
}
int s = 0, e = 0;
StringBuffer result = new StringBuffer((int) str.length()*2);
while ((e = str.indexOf(pattern, s)) >= 0) {
result.append(str.substring(s, e));
result.append(replace);
s = e + pattern.length();
}
result.append(str.substring(s));
return result.toString();
}
String getOptions( java.sql.Connection conn, String sql, boolean isSearch, boolean isRequired, String selectedValue ) {
String sOptions = "";
String sSel = "";
if ( isSearch ) {
sOptions += "<option value=\"\">All</option>";
}
else {
if ( ! isRequired ) {
sOptions += "<option value=\"\"></option>";
}
}
try {
java.sql.Statement stat = conn.createStatement();
java.sql.ResultSet rs = null;
rs = openrs (stat, sql);
while (rs.next() ) {
String id = toHTML( rs.getString(1) );
String val = toHTML( rs.getString(2) );
if ( id.compareTo(selectedValue) == 0 ) {
sSel = "SELECTED";
}
else {
sSel = "";
}
sOptions += "<option value=\""+id+"\" "+sSel+">"+val+"</option>";
}
rs.close();
stat.close();
}
catch (Exception e) {}
return sOptions;
}
String getOptionsLOV( String sLOV, boolean isSearch, boolean isRequired, String selectedValue ) {
String sSel = "";
String slOptions = "";
String sOptions = "";
String id = "";
String val = "";
java.util.StringTokenizer LOV = new java.util.StringTokenizer( sLOV, ";", true);
int i = 0;
String old = ";";
while ( LOV.hasMoreTokens() ) {
id = LOV.nextToken();
if ( ! old.equals(";") && ( id.equals(";") ) ) {
id = LOV.nextToken();
}
else {
if ( old.equals(";") && ( id.equals(";") ) ) {
id = "";
}
}
if ( ! id.equals("") ) { old = id; }
i++;
if (LOV.hasMoreTokens()) {
val = LOV.nextToken();
if ( ! old.equals(";") && (val.equals(";") ) ) {
val = LOV.nextToken();
}
else {
if (old.equals(";") && (val.equals(";"))) {
val = "";
}
}
if ( val.equals(";") ) { val = ""; }
if ( ! val.equals("")) { old = val; }
i++;
}
if ( id.compareTo( selectedValue ) == 0 ) {
sSel = "SELECTED";
}
else {
sSel = "";
}
slOptions += "<option value=\""+id+"\" "+sSel+">"+val+"</option>";
}
if ( ( i % 2 ) == 0 ) sOptions += slOptions;
return sOptions;
}
String getValFromLOV( String selectedValue , String sLOV) {
String sRes = "";
String id = "";
String val = "";
java.util.StringTokenizer LOV = new java.util.StringTokenizer( sLOV, ";", true);
int i = 0;
String old = ";";
while ( LOV.hasMoreTokens() ) {
id = LOV.nextToken();
if ( ! old.equals(";") && ( id.equals(";") ) ) {
id = LOV.nextToken();
}
else {
if ( old.equals(";") && ( id.equals(";") ) ) {
id = "";
}
}
if ( ! id.equals("") ) { old = id; }
i++;
if (LOV.hasMoreTokens()) {
val = LOV.nextToken();
if ( ! old.equals(";") && (val.equals(";") ) ) {
val = LOV.nextToken();
}
else {
if (old.equals(";") && (val.equals(";"))) {
val = "";
}
}
if ( val.equals(";") ) { val = ""; }
if ( ! val.equals("")) { old = val; }
i++;
}
if ( id.compareTo( selectedValue ) == 0 ) {
sRes = val;
}
}
return sRes;
}
String checkSecurity(int iLevel, javax.servlet.http.HttpSession session, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpServletRequest request){
try {
Object o1 = session.getAttribute("UserID");
Object o2 = session.getAttribute("UserRights");
boolean bRedirect = false;
if ( o1 == null || o2 == null ) { bRedirect = true; }
if ( ! bRedirect ) {
if ( (o1.toString()).equals("")) { bRedirect = true; }
else if ( (new Integer(o2.toString())).intValue() < iLevel) { bRedirect = true; }
}
if ( bRedirect ) {
response.sendRedirect("Login.jsp?querystring=" + toURL(request.getQueryString()) + "&ret_page=" + toURL(request.getRequestURI()));
return "sendRedirect";
}
}
catch(Exception e){};
return "";
}
//
// Filename: Login.jsp
// Generated with CodeCharge v.1.2.0
// JSP.ccp build 05/21/2001
//
static final String sFileName = "Login.jsp";
String LoginAction(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpSession session, javax.servlet.jsp.JspWriter out, String sAction, String sForm, java.sql.Connection conn, java.sql.Statement stat) throws java.io.IOException {
String sLoginErr = "";
try {
final int iloginAction = 1;
final int ilogoutAction = 2;
String transitParams = "";
String sQueryString = "";
String sPage = "";
String sSQL="";
int iAction = 0;
if ( sAction.equals("login") ) iAction = iloginAction;
if ( sAction.equals("logout") ) iAction = ilogoutAction;
switch (iAction) {
case iloginAction: {
// Login action
String sLogin = getParam( request, "Login");
String sPassword = getParam( request, "Password");
java.sql.ResultSet rs = null;
rs = openrs( stat, "select member_id, member_level from members where member_login =" + toSQL(sLogin, adText) + " and member_password=" + toSQL(sPassword, adText));
if ( rs.next() ) {
// Login and password passed
session.setAttribute("UserID", rs.getString(1));
session.setAttribute("UserRights", rs.getString(2));
sQueryString = getParam( request, "querystring");
sPage = getParam( request, "ret_page");
if ( ! sPage.equals(request.getRequestURI() ) && ! "".equals(sPage)) {
try {
if ( stat != null ) stat.close();
if ( conn != null ) conn.close();
}
catch ( java.sql.SQLException ignore ) {}
response.sendRedirect(sPage + "?" + sQueryString);
return "sendRedirect";
}
else {
try {
if ( stat != null ) stat.close();
if ( conn != null ) conn.close();
}
catch ( java.sql.SQLException ignore ) {}
response.sendRedirect("ShoppingCart.jsp");
return "sendRedirect";
}
}
else sLoginErr = "Login or Password is incorrect.";
rs.close();
break;
}
case ilogoutAction: {
// Logout action
session.setAttribute("UserID", "");
session.setAttribute("UserRights", "");
break;
}
}
}
catch (Exception e) { out.println(e.toString()); }
return (sLoginErr);
}
void Login_Show(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpSession session, javax.servlet.jsp.JspWriter out, String sLoginErr, String sForm, String sAction, java.sql.Connection conn, java.sql.Statement stat) throws java.io.IOException {
try {
String sSQL="";
String transitParams = "";
String sQueryString = getParam( request, "querystring");
String sPage = getParam( request, "ret_page");
out.println(" <table style=\"\" border=1>");
out.println(" <tr>\n <td style=\"background-color: #336699; text-align: Center; border-style: outset; border-width: 1\" colspan=\"2\"><font style=\"font-size: 12pt; color: #FFFFFF; font-weight: bold\">Enter login and password</font></td>\n </tr>");
if ( sLoginErr.compareTo("") != 0 ) {
out.println(" <tr>\n <td colspan=\"2\" style=\"background-color: #FFFFFF; border-width: 1\"><font style=\"font-size: 10pt; color: #000000\">"+sLoginErr+"</font></td>\n </tr>");
}
sLoginErr="";
out.println(" <form action=\""+sFileName+"\" method=\"POST\">");
out.println(" <input type=\"hidden\" name=\"FormName\" value=\"Login\">");
if ( session.getAttribute("UserID") == null || ((String) session.getAttribute("UserID")).compareTo("") == 0 ) {
// User did not login
out.println(" <tr>\n <td style=\"background-color: #FFEAC5; border-style: inset; border-width: 0\"><font style=\"font-size: 10pt; color: #000000\">Login</font></td><td style=\"background-color: #FFFFFF; border-width: 1\"><input type=\"text\" name=\"Login\" maxlength=\"50\" value=\""+toHTML(getParam( request, "Login"))+"\"></td>\n </tr>");
out.println(" <tr>\n <td style=\"background-color: #FFEAC5; border-style: inset; border-width: 0\"><font style=\"font-size: 10pt; color: #000000\">Password</font></td><td style=\"background-color: #FFFFFF; border-width: 1\"><input type=\"password\" name=\"Password\" maxlength=\"50\"></td>\n </tr>");
out.print(" <tr>\n <td colspan=\"2\"><input type=\"hidden\" name=\"FormAction\" value=\"login\"><input type=\"submit\" value=\"Login\">");
out.println("<input type=\"hidden\" name=\"ret_page\" value=\""+sPage+"\"><input type=\"hidden\" name=\"querystring\" value=\""+sQueryString+"\"></td>\n </form>\n </tr>");
}
else {
// User logged in
String sUserID = dLookUp( stat, "members", "member_login", "member_id =" + session.getAttribute("UserID"));
out.print(" <tr><td style=\"background-color: #FFFFFF; border-width: 1\"><font style=\"font-size: 10pt; color: #000000\">"+sUserID+" "+"</font><input type=\"hidden\" name=\"FormAction\" value=\"logout\"/><input type=\"submit\" value=\"Logout\"/>");
out.print("<input type=\"hidden\" name=\"ret_page\" value=\""+sPage+"\"><input type=\"hidden\" name=\"querystring\" value=\""+sQueryString+"\">");
out.println("</td>\n </form>\n </tr>");
}
out.println(" </table>");
}
catch (Exception e) { out.println(e.toString()); }
}
private static java.util.Vector _jspx_includes;
static {
_jspx_includes = new java.util.Vector(1);
_jspx_includes.add("/Common.jsp");
}
public java.util.List getIncludes() {
return _jspx_includes;
}
public void _jspService(HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, ServletException {
JspFactory _jspxFactory = null;
javax.servlet.jsp.PageContext pageContext = null;
HttpSession session = null;
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = this;
JspWriter _jspx_out = null;
try {
_jspxFactory = JspFactory.getDefaultFactory();
response.setContentType("text/html;charset=ISO-8859-1");
pageContext = _jspxFactory.getPageContext(this, request, response,
null, true, 8192, true);
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
_jspx_out = out;
boolean bDebug = false;
String sAction = getParam( request, "FormAction");
String sForm = getParam( request, "FormName");
String sLoginErr = "";
java.sql.Connection conn = null;
java.sql.Statement stat = null;
String sErr = loadDriver();
conn = cn();
stat = conn.createStatement();
if ( ! sErr.equals("") ) {
try {
out.println(sErr);
}
catch (Exception e) {}
}
if ( sForm.equals("Login") ) {
sLoginErr = LoginAction(request, response, session, out, sAction, sForm, conn, stat);
if ( "sendRedirect".equals(sLoginErr)) return;
}
out.write(" \r\n<html>\r\n<head>\r\n<title>Book Store</title>\r\n<meta name=\"GENERATOR\" content=\"YesSoftware CodeCharge v.1.2.0 / JSP.ccp build 05/21/2001\"/>\r\n<meta http-equiv=\"pragma\" content=\"no-cache\"/>\r\n<meta http-equiv=\"expires\" content=\"0\"/>\r\n<meta http-equiv=\"cache-control\" content=\"no-cache\"/>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\r\n</head>\r\n<body style=\"background-color: #FFFFFF; color: #000000; font-family: Arial, Tahoma, Verdana, Helveticabackground-color: #FFFFFF; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica\">\r\n");
JspRuntimeLibrary.include(request, response, "Header.jsp", out, true);
out.write("<center>\r\n <table>\r\n <tr>\r\n \r\n <td valign=\"top\">\r\n");
Login_Show(request, response, session, out, sLoginErr, sForm, sAction, conn, stat);
out.write("\r\n guest/guest<br>\r\nadmin/admin\r\n </td>\r\n </tr>\r\n </table>\r\n\r\n");
JspRuntimeLibrary.include(request, response, "Footer.jsp", out, true);
out.write("\r\n<center><font face=\"Arial\"><small>This dynamic site was generated with <a href=\"http://www.codecharge.com\">CodeCharge</a></small></font></center>\r\n</body>\r\n</html>\r\n");
out.write("\r\n");
if ( stat != null ) stat.close();
if ( conn != null ) conn.close();
out.write("\r\n");
} catch (Throwable t) {
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
out.clearBuffer();
if (pageContext != null) pageContext.handlePageException(t);
} finally {
if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext);
}
}
}