📄 loginhelper.java
字号:
package oracle.otnsamples.AQ.Helper;
/**
* @author Rajat Gupta
* @version 1.0
*
* Name of the Application : LoginHelper.java
* Development Environment : Oracle 9i JDeveloper
* Creation/Modification History :
*
* Rajat Gupta 15-Jan-2001 Created
*
*/
// Util Imports
import java.util.Hashtable;
import java.util.Vector;
// Other files
import oracle.otnsamples.AQ.DataBase.DBConnect;
/**
* This class helps in logging a customer or an admin. It checks if the provided
* UserName/Password is valid or not.
* If the user is valid, then the Name of the User is returned.
* If the user is not valid, then an exception is generated and the proper error
* message is shown to the User.
*/
public class LoginHelper{
/**
* Empty Constructor
*/
public LoginHelper(){
}
/**
* This method validates the User (Customer/Admin) entered. It takes as input parameters the
* loginID, password of User and also the type of User. An Exception is thrown
* on invalid login/password.
*
* @param p_login Login ID entered by the User
* @param p_password Password entered by the User
* @param p_user Type of User
* @exception Exception if User is not valid
* @return If valid User, then the Name of the User is returned
* @see DBConnect.java
*/
static public Hashtable validateUser(String p_login, String p_password, String p_user)
throws Exception{
Hashtable userinfo = new Hashtable();
Vector data = null;
String query = "";
// Gets the Instance of DBConnect
DBConnect dbInstance = DBConnect.getInstance();
if (p_user.equals("Customer")){
// If the user is of type customer then validate him using the Customer_Master table.
query = "SELECT INITCAP(customer_name) FROM Customer_Master WHERE"
+" LOWER(TRIM(customer_id)) = LOWER(TRIM('"+ p_login +"'))"
+ " AND LOWER(password) = LOWER('"+ p_password + "')";
}else if ((p_user.equals("Computer")) || (p_user.equals("Printer"))
|| (p_user.equals("Retail"))){
// If the user is of type Computer or Printer or Retail then validate
// him using the Admin_Master table.
query = "SELECT INITCAP(admin_name) FROM Admin_Master WHERE"
+" LOWER(TRIM(admin_id)) = LOWER(TRIM('"+ p_login +"')) AND"
+" LOWER(admin_password) = LOWER('"+ p_password + "')";
}
// Get the data from the resultset in the form of a String array
// stored in Vector.
data = dbInstance.executeQuery(query, p_user);
// Validate the user.
isValid(data);
// Get the userName and store it in a Hashtable.
String[] userName = (String[])data.elementAt(0);
userinfo.put("Name",userName[0]);
return userinfo;
}
/**
* This method checks is the User is valid or not. If the Size of the Vector
* passed is 1, then an entry is matched for the particular Username/Password
* in the database. If the size of Vector is 0 or more than 1, then the User
* is not valid and an exception is thrown.
*
* @exception Exception thrown if the Username/Password provided is invalid
* @param p_data Vector Passed that Contains the Name of the User if valid
*/
private static void isValid(Vector p_data) throws Exception{
if (p_data.size() != 1){
throw new Exception("AQ-1000");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -