SQL Code
public String CheckLogin(String Username, String Password) throws RemoteException
{
String answer = null;
try
{
statement = link.createStatement();
results = statement.executeQuery("SELECT * FROM USERS WHERE USERNAME ='"+Username+ "'");
if (results.next()) {
String dbpassword = results.getString("PASSWORD");
String bdtype = results.getString("ACCOUNT_TYPE");
if (dbpassword.equals(Password))
{
answer = "User Found";
}
else {
answer= "Password Wrong";
}}
else {
answer = "Username and/or Password Wrong";
} }
catch (Exception e) {
System.out.println("Exception occured ---" + e);
}
return answer;
}}
Hibernate Code
public static Client checkLogin(Session session,ClientDTO client){
String answer = null;
Client user = new Client();
String queryString = "from NMEAData where Username = :Username";
Query query = session.createQuery(queryString);
query.setString("Username", client.getUsername());
user = (Client) query.uniqueResult();
if (client.getUsername().equals(user.getUsername()))
{
if (client.getPassword().equals(user.getPassword()))
{
answer = "User Found";
System.out.println(answer);
}
else {
answer= "Password wrong";
System.out.println(answer);
}}
else {
answer = "Username and/or password incorrect";
System.out.println(answer);
}
System.out.println(user.getUsername());
return user;
}
|