/Users/lyon/j4p/src/net/server/servlets/Authorization.java

1    package net.server.servlets; 
2     
3    /** 
4     * The Authorization class encapsulates the functionality 
5     * required to validate a user id and password. 
6     * 
7     * @author Robert Lysik 
8     * @version 1.00 
9     */ 
10   class Authorization { 
11    
12       /** 
13        * This is the default constructor for the 
14        * Authorization class. 
15        */ 
16       public Authorization() { 
17    
18       } 
19    
20       /** 
21        * The verify function takes two parameters, the user id 
22        * and password, and performs a query against the user 
23        * database. If a matching record is found then the user is 
24        * validated and true is returned, otherwise flase is returned. 
25        * 
26        * @param String user id 
27        * @param String password 
28        */ 
29       public boolean verify(String UserId, String password) { 
30           String sqlQuery = "select count(*) from udbTable where " + 
31                   "userId = '" + UserId + "' and " + 
32                   "password = '" + password + "'"; 
33           int recordMatchCount = 0, 
34                   columnIndex = 1; 
35    
36           SqlBean sb = new SqlBean(); 
37    
38           // The UDB ODBC connection must be defined, this 
39           // is the user database which will be used for validation of 
40           // the user id and password passed in as parameters. 
41           sb.setUrl("jdbc:odbc:udb"); 
42    
43           sb.init(); 
44    
45           recordMatchCount = sb.getResultSetIntegerColumnData(sb.query(sqlQuery), 
46                   columnIndex); 
47    
48           sb.close(); 
49    
50           // return true if a matching record has been found. 
51           return (recordMatchCount > 0) ? true : false; 
52       } 
53   }